Pi3D

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

Just put v2.23 onto github and pypi.python.org Most recent versions are minor improvements and fixes. This version has some utility methods in the Shape class to make it a bit easier to get direction vectors and Euler rotations from local to global frames of ref, which might be useful in more gamy applications. There's an updated TigerTank demo which uses all the recent features. Here's a link to a stress test video. (on laptop, with 20 enemies it won't run at any speed on RPi even on v3 (but it seems fine with 8.))
fr01090.jpg (19.54 KiB) Viewed 4016 times

Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Pi3D

Hi Fellow and Fellowette Pi3D Gurus and Nutjobs!

It's been faaaaar too long since I'd perused this thread and I'm glad to see that things are still being improved and expanded. I've been off teaching a variety of STEM things for quite a while and am only now getting back to Pi3D because I'm teaching 3D graphics as part of a computing technology course in high school to some rabid protogeeks who can't get enough of this 3D stuff.

I'd been working on an orrery in Pi3D waaaaay back when, and had gotten all of the planets, the Moon, the major moons of other planets, the largest asteroids, and some comets working. One thing that I didn't have time to get working was decent-looking rings around Saturn and would like to finish that. My initial idea was to use a tube with a very short length (effectively a narrow thickness) and a very large thickness, resulting in an extremely thin "washer" - the thickness of the real rings is about the height of a two-story house, but millions of miles wide! I was then going to apply a simple ring image to each side of the "washer" as a texture, flipped for the top and bottom of the "washer's" surfaces. However, when attempting to apply the texture:
Saturn_Rings.jpg (231.81 KiB) Viewed 3965 times
it didn't map to the "washer's" surfaces evenly, and is progressively warped into a squiggly path that dribbles off one edge of the "washer":
Bad_Rings.jpg (83.75 KiB) Viewed 3965 times
That would be fine if I were trying to emulate Salvador Dali's "The Persistence of Memory" (the one with the melting clocks and watches), but I'm not. There are .obj models for the rings that would work, but of course, that would just be too easy. Any suggestions for making the texture-mapped Tube/"washer" approach work would be more than welcome.

In a related vein, I've downloaded some of the data from the ESA Gaia satellite that's been collecting it on upwards of 1.7 billion stars and other objects for the past five years, and was just released to the public. I'd like to create a Pi3D-based viewer that would also be the basis for the astronomical navigation engine of my Pi-finity! STEM 3D educational game that remains the software project with the longest gestation period in history I need to figure out how to convert the astronomical format of the data to a form where it can be readily displayed via Pi3D. Basically, each star is located by its azimuth, elevation/altitude, and distance, and its visibility is also determined by its brightness/magnitude.

Obviously, even using minimal locating data per star/object, it would be impossible to display every star/object at one time, but that's not necessary as those stars/objects that are dimmer and further away can be ignored unless the viewer's position is significantly moved in their direction, away from the Earth and our Sun (at the distances of other stars, the 93 million mile difference is insignificant). If anyone else has already converted astronomical position data to Pi3D Cartesian coordinates, or created a viewer that can display celestial bodies using astronomical format directly, that would be nice to know.

Thanks and All the Best,
Jim
The best things in life aren't things ... but, a Pi comes pretty darned close!
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

Jim, great to hear from you again. I'll have a look at the tube distortion issue, it looks like the uv texture coordinates are being calculated wrong!

On the realistic star map issue, I did just the thing you're looking for (for a local raspberry jam a couple of years ago) and replaced the existing Starfield.py demo https://github.com/pi3d/pi3d_demos/blob ... arfield.py
It has a slightly sophisticated bit of code to select the nearest few thousand stars and reset the locations, pointsizes and colours of the points and uses a special version of the point shader (to essentially make the points circular and different colours)

PS tricky code is hidden away in different file https://github.com/pi3d/pi3d_demos/blob/master/stars.py

PPS here's a youtube of the demo (with the commented bits of startsystem.py left in. I didn't want to clutter pi3d_demos with the models or textures) https://www.youtube.com/watch?v=y7mmVRjQBFs (A lot of the stars are not visible in the lower resolution video version)

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

OK, the problem is that the Tube class uses Shape._lathe() to construct itself and that convenience method is designed to cope with any shape with rotational symmetry (and or shifted as in helix). This is used for Sphere, Cylinder, Cone, Helix, Tube, Torus, TCone, Lathe and it assumes that the Texture is going to be wrapped around the shape in a reasonably seamless way - see the Shapes demo. But I agree that this isn't the best way to produce a good flat tube or cylinder. Extrude would be better but can't cope with a hollow shape. What's needed is is something like the amended code at the bottom, which I will put into the next release (probably later today as there's a bug fix needed on TextBlock).

But. I think the best way to do the rings would be to make the image into a png with transparent areas where it's black and use pi3d.Plane. That way you will get reasonably smooth edges but only have to render 4 triangles (a Tube with 64 edges still looks a bit polygonal but needs 512 triangles)

Code: Select all

shader = pi3d.Shader('uv_bump')
tex = pi3d.Texture('textures/Saturn_Rings.png')
norm = pi3d.Texture('textures/Saturn_Rings.png', normal_map=5.0) # this is a nifty way of getting surface texture normal maps
rings = pi3d.Plane(w=100.0, h=100.0, z=100.0)

while display.loop_running():
rings.rotateIncX(0.11)
rings.rotateIncZ(0.1)
rings.draw()

produces (and, presumably, some of those gaps should be transparent, which is easy to do)
Screenshot07.jpg (45.45 KiB) Viewed 3921 times

Code: Select all

inr = 15.0
otr = 50.0
edges = 32
step = math.pi * 2.0 / edges
ht = 10.0

verts = []
norms = []
uvs = []
faces = []

normdirs = ((0, 1), (1, 0), (0, -1), (-1, 0)) # up, out, down, in
for i in range(edges + 1):
for j, (xz, y) in enumerate(((inr, ht), (otr, ht), # up
(otr, ht), (otr, -ht), # out
(otr, -ht), (inr, -ht), # down
(inr, -ht), (inr, ht))): # in
s = math.sin(i * step)
c = math.cos(i * step)
verts += [(xz * s, y, xz * c)]
n = normdirs[j // 2]
norms += [(n[0] * s, n[1], n[0] * c)]
if n[0] == 0: # top or bottom
uvs += [(0.5 * (1.0 + verts[-1][0] / otr), 0.5 * (1.0 + verts[-1][2] / otr))]
else:
uvs += [(i / edges, 0.5 * (1.0 + y / ht))]
if i < (edges):
for a, b, c in ((0, 1, 8), (1, 9, 8), (2, 3, 10), (3, 11, 10),
(4, 5, 12), (12, 5, 13), (6, 7, 14) , (7, 15, 14)):
f_off = i * 8
faces += [(a + f_off, b + f_off, c + f_off)]

rings = pi3d.Shape(None, None, "", 0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0)
rings.buf = [pi3d.Buffer(rings, verts, uvs, faces, norms)]


Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Pi3D

I figured you would see my questions within a week or three, but I guess timing is everything!

I did try running the Starfield.py demo, noticing it right away when I downloaded the current Pi3D release, but I was on a Windoze PC at school at the time, and got the following highly informative response:

Code: Select all

Traceback (most recent call last):
DISPLAY = pi3d.Display.create(x=50, y=50, near=0.05, far=100000, frames_per_second=20, samples=4) #note big far and small near plane values
display.opengl.create_display(x, y, w, h, depth=depth, samples=samples, layer=layer, display_config=display_config)
assert self.context != EGL_NO_CONTEXT and self.context is not None
AssertionError
I assume that there's something missing/broken in the Windoze EGL DLL stuff - is it a never-gonna-work limitation, or something that can eventually be fixed? I'll be trying it out on my brand-stinkin'-new Pi 3B0+ (with star-studded mud-guards, for the Firesign Theater freaks Out There ) this weekend to enjoy zooming around the galaxy at will.

As for the rings issue, you can always rely on me to find the most obscure corner cases where five triangles come together at a point inside a completely irregular polyhedron! I did try the simple solution to the rings you provided, and after changing:

Code: Select all

while display.loop_running():
to the case used in all of the demos:

Code: Select all

while DISPLAY.loop_running():
it worked just fine. Of course, now you've made me have to work on transparency earlier than I was going to (it would be necessary to cast separate ring shadows properly on Saturn - at least I think that will work). However, I am _not_ complaining, since I wouldn't have gotten that far until the rings displayed properly anyway.

Thank you, Sir, and enjoy the Yank Knighthood - that and \$5 will get you an over-sweetened Starblechs brew!

All the Best,
Jim
Fri Apr 27, 2018 6:39 am
On the realistic star map issue, I did just the thing you're looking for (for a local raspberry jam a couple of years ago) and replaced the existing Starfield.py demo https://github.com/pi3d/pi3d_demos/blob ... arfield.py
It has a slightly sophisticated bit of code to select the nearest few thousand stars and reset the locations, pointsizes and colours of the points and uses a special version of the point shader (to essentially make the points circular and different colours)

PS tricky code is hidden away in different file https://github.com/pi3d/pi3d_demos/blob/master/stars.py

PPS here's a youtube of the demo (with the commented bits of startsystem.py left in. I didn't want to clutter pi3d_demos with the models or textures) https://www.youtube.com/watch?v=y7mmVRjQBFs (A lot of the stars are not visible in the lower resolution video version)
The best things in life aren't things ... but, a Pi comes pretty darned close!
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

Jim, I think the area covered by the HYG-database is fairly local in galactic terms. Flying around the StarField.py demo makes you realize how gigantic the universe. To fly though the stars so they stream past sci-fi like you need to press w enough times to get up to a step size per frame of about 3 parsec, that's about 600 lightyears per second or 20 billion times the speed of light! It still takes several minutes to get across the Milky Way and hours to reach Andromeda.

Did you put the relevant dlls in the demos folder? http://pi3d.github.io/html/ReadMe.html#windows (I can see issues with downloading dll files from github on a school computer) I'm looking at the pros and cons of using a standardized wrapper such as SDL2. It seems to be slower on the RPi but maybe I can leave an option to pick up the broadcom drivers directly...

Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Pi3D

So, I generated a .png of the rings with transparency for the darker pixels. I got the rings to display via a Plane with the image applied as a texture, positioned centered on a sphere for Saturn (named saturn) with its texture applied. I can even rotate the rings around the x axis so that they're at an angle relative to the equator of Saturn, with rx=85.0 in the Plane instantiation corresponding to the plane of the rings cutting near the equator of Saturn (close to 90.0, but, still visible nearly on edge). I can rotate Saturn slowly about its y axis using saturn.rotateIncY(0.1), ala Earth.py.

However, I can't figure out how to get the rings to rotate at nearly the same rate as Saturn, around Saturn's y axis using rings.rotateIncY(0.1). Instead, they rotate around the y axis of the image, which is essentially the absolute z axis after the rotation of the image around its x axis by rx=85.0.

Here's the code:

Code: Select all

#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals

""" Draws Saturn as a textured Sphere, rotating around its y axis, and draws its rings as a
textured Plane through Saturn's equator, also rotating around Saturn's y axis.
"""
# just allow this to run in a subdirectory
import demo
import pi3d
# Load diplay, nearly full screen
DISPLAY = pi3d.Display.create(x=20, y=20, background=(0.0, 0.0, 0.1, 1.0))
##########################################
tex = pi3d.Texture('textures/Saturn_Rings_Transparent_15.png')
norm = pi3d.Texture('textures/Saturn_Rings_Transparent_15.png', normal_map=5.0) # this is a nifty way of getting surface texture normal maps
saturnimg = pi3d.Texture("textures/Saturn_1024x512.jpg")
name="saturn", z=100.0)
rings = pi3d.Plane(w=100.0, h=100.0, z=100.0, rx=85.0)

while DISPLAY.loop_running():
saturn.rotateIncY(-0.2)
rings.rotateIncY(1.0)
rings.draw()

As for the Starfield.py problem, the DLLs are loaded on all Windows PCs, and code such as Earth.py runs fine. I haven't tried all of the other demos, but will this weekend to see if there's a pattern.

Thanks and All the Best,
Jim
The best things in life aren't things ... but, a Pi comes pretty darned close!
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

Jim, I'll run this in the morning and show you what to do but basically the best way of doing things like this is using the parent-child system (The gun and turret of the TigerTank demo uses this, and probably others) So what you want is probably for both Saturn and its rings to be children of a 'empty' objects like:

empty0
..|-Saturn
..|-empty1
......|-rings

so empty1 is rotated slightly relative to empty0. The displacements, rotations and scales of children are all applied relative to their parents so empty0 can orbit the sun while Saturn rotates round it and empty1 could precess a bit relative to empty0 while the rings rotate around it.

Might be clearer with some code...

Also thanks for the note on the Starfield demo on windows I will check that out tomorrow too.

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

This kind of thing. The default size of a Triangle is side length 1 so sometimes you need to specify the corners or set_alpha(0.0) to hide them.

Code: Select all

...
saturnimg = pi3d.Texture("textures/Saturn_1024x512.jpg")
empty0 = pi3d.Triangle(z=100.0) # displaced
empty1 = pi3d.Triangle(rx=85.0) # no displacement but rotated
saturn = pi3d.Sphere(radius=20, slices=24, sides=24, name="saturn") # no displacement
saturn.set_draw_details(shader, [saturnimg]) # needs to be done here rather than in draw()
rings = pi3d.Plane(w=100.0, h=100.0) # no displacment

while DISPLAY.loop_running():
#empty0.rotateIncY(0.01) # wobble rings axis of rotation
saturn.rotateIncY(-0.2)
rings.rotateIncZ(1.0)
empty0.draw()


Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

Checked the Starfield.py demo on windows and noticed that Diplay.create() has the samples argument. This improves antialiassing for white lines on a black background, unfortunately it doesn't seem to have been implemented in the ANGLE software (maybe I should checkout the latest source code and recompile it..) It worked when I just removed ",samples=4".

Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Pi3D

Sun May 06, 2018 7:28 am
Checked the Starfield.py demo on windows and noticed that Diplay.create() has the samples argument. This improves antialiassing for white lines on a black background, unfortunately it doesn't seem to have been implemented in the ANGLE software (maybe I should checkout the latest source code and recompile it..) It worked when I just removed ",samples=4".
YAY!!! That works beautifully - thanks! It would have taken me more time than it took whomever implemented OpenGL ES on Windows in order to figure this out. I still need to look at the new GAIA data to figure out how to convert it to your stars data file format - there are something like 40 fields and it's not immediately obvious which are the azimuth and altitude/declination angles, ecliptic and vector references, distances, apparent brightness, units, etc. There are about 60,000 files, each an average of about 14 MBs in size!
Sat May 05, 2018 8:42 am
This kind of thing. The default size of a Triangle is side length 1 so sometimes you need to specify the corners or set_alpha(0.0) to hide them.
More YAY!!! That got it working. I couldn't use the technique for the rings used to get the Moon and "Death Star" (that's what I've nicknamed it) orbiting around the Earth and Moon, respectively, as occurs in Earth.py.

Now, I just need to get one more thing working, and that's casting of the shadows of the rings on the surface of Saturn. Since the default lighting didn't work, I tried setting a pi3d.Light(...), but that didn't seem to provide the shadows, either.

Here's the transparent rings file - it's not exactly symmetric, and so doesn't revolve quite around Saturn's center (not noticeable at more realistic, slower speeds), and I had to squish it to 1/8th of the original size because of forum upload size limitations:
Saturn_Rings_Transparent_15_25%.png (76.13 KiB) Viewed 3743 times
Here's the code - note that when run, Saturn is visible through the largest gap between rings (the Cassini Division), as well as through the more sparse innermost rings - very satisfying (your ring wobble option is a great touch!):

Code: Select all

#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals

"""
Rings.py
"""
# just allow this to run in a subdirectory
import demo
import pi3d
# Load diplay, nearly full screen
DISPLAY = pi3d.Display.create(x=20, y=20, background=(0.0, 0.0, 0.1, 1.0))
light = pi3d.Light(lightpos=(1.0, 0.0, 0.1))
##########################################
tex = pi3d.Texture('textures/Saturn_Rings_Transparent_15_25%.PNG')
norm = pi3d.Texture('textures/Saturn_Rings_Transparent_15_25%.PNG', normal_map=5.0)
# this is a nifty way of getting surface texture normal maps
rings = pi3d.Plane(w=100.0, h=100.0, z=100.0)
saturnimg = pi3d.Texture("textures/Saturn_1024x512.jpg")
empty0 = pi3d.Triangle(z=100.0) # displaced
empty1 = pi3d.Triangle(rx=85.0) # no displacement but rotated
saturn = pi3d.Sphere(radius=20, slices=24, sides=24, name="saturn")
# no displacement
# needs to be done here rather than in draw()
rings = pi3d.Plane(w=100.0, h=100.0)
# no displacment

while DISPLAY.loop_running():
#empty0.rotateIncY(0.01) # wobble rings axis of rotation
saturn.rotateIncY(-0.2)
rings.rotateIncZ(1.0)
empty0.draw()

Thanks for all of this fun and All the Best,
Jim
The best things in life aren't things ... but, a Pi comes pretty darned close!
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

Hmm, there is a ShadowCaster class and shader that works ok for shadows cast onto the ground or other objects (see CastShadows and TigerShadow demos) but I can't get it to work for your rings (and I can't really remember how it works) I will have a look later.

Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Pi3D

Tue May 08, 2018 2:58 pm
Hmm, there is a ShadowCaster class and shader that works ok for shadows cast onto the ground or other objects (see CastShadows and TigerShadow demos) but I can't get it to work for your rings (and I can't really remember how it works) I will have a look later.
Whoa! When I tried running either of those on an i5 with 8 GBs of RAM, they crashed the 'puter hard, as in the Win10 BSOD (which I'd never had the "pleasure" of seeing before). Earth.py and my Rings.py run fine, but I need to figure out if there are other demos that are problematic before I unleash them on the unwashed (aka students ... and me, late at night).

From the And Now for Something Completely Different Department: it occurred to me, being the pedantic, pedagogical pedestrian that I am, that we may need something to fill in the absolute-beginner tutorial role for learning 3-D graphics via Pi3D, as I don't recall seeing anything like that. The Pi3D docs are great reference pages, and the demos provide the working examples, although they need more detailed comments for those inexperienced with 3-D. That also goes for those of us who have forgotten the intricacies of the Original Flavor GL we cut our teeth on, via an early pair of SGI Iris 2400s - I go back to before there was automagical hidden point/line/surface removal!

I was thinking about adapting to Pi3D the 3-D graphics and WebGL tutorial at:

http://learningwebgl.com/blog/?page_id=1217

Then, I could expand it to include the Pi3D demos once the really simple stuff has been beaten to death. However, first I have to get through finals week with my students later this month, and then I'll have the Summer to goof off ... well, that, plus two university scientific research and engineering projects that will lead to published papers, for which I'm being funded via grants.
The best things in life aren't things ... but, a Pi comes pretty darned close!
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

That sounds bad. There's lots of scope for unsafe operations patching pointers and untyped python variables into gl functions. What python are you running and is it 64 or 32 bits? This laptop is also i5 8Gb with windows 10 - but it's in as small a partition as I thought I could get away with and it seems to be unable to update itself to the latest version, not sure if that's relevant.

Having an easy to understand intro would be fantastic. A lot of the details of OpenGL are hidden away in pi3d so it's a bit messy, but still possible, to show how it's working. There are the two videos that Peter Farrel made (which come up high on a youtube search for pi3d) and the book on pi3d.github.io

Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Pi3D

Thu May 10, 2018 7:02 pm
That sounds bad. There's lots of scope for unsafe operations patching pointers and untyped python variables into gl functions. What python are you running and is it 64 or 32 bits? This laptop is also i5 8Gb with windows 10 - but it's in as small a partition as I thought I could get away with and it seems to be unable to update itself to the latest version, not sure if that's relevant.
I'm running Python 3.6.5 64-bit on Windoze 10. Amazing, Buckfast Abbey, and Starfield run fine, and I get the feeling the other less taxing demos will probably also run. It's likely when there are lots of objects, vertices, edges, and faces, and we get into complex geometries involving shading that things can go South. I'll see if I can slice and dice the demos that are failing to reduce their resource demands, or even do some actual instrumentation and debugging. TBH, I'm still amazed that _any_ of this stuff works at all, as it pokes Murphy in both eyes with insane malice.
Thu May 10, 2018 7:02 pm
Having an easy to understand intro would be fantastic. A lot of the details of OpenGL are hidden away in pi3d so it's a bit messy, but still possible, to show how it's working. There are the two videos that Peter Farrel made (which come up high on a youtube search for pi3d) and the book on pi3d.github.io
I thought I saw mention of a Pi3D book, probably back when it was announced, but I didn't realize that there was a GitHub page above the level of the pages for the docs and demos, so I never saw the link to the book. When I referenced the WebGL tutorial, I was thinking more about the 3-D part of it, not the WebGL part, and substituting Pi3D equivalents of the WebGL demos.

I think it's important for noobs to understand the fundamentals of 3-D space and how points, edges, and triangles are used to build everything else. I''m one of those crazies who actually teaches all four STEM subjects (Broadfield - Physical, Earth, Biology, Chemistry, Physics, Geology, Astronmy, Ecology, etc.) Science, Technology, Engineering, and Mathematics, both individually and integrated across courses. I think it's critical to get kids to think of 3-D applied to the real world as much and as early as possible, rather than spend too much time in the abstractions of 2-D that they routinely find confusing and arbitrary.

Unlike the Pi3D book, I would provide more of the fundamentals up front for the math, computing hardware and software, Python basics (seems funny using those two programming language words together), the 3-D coordinate system, how points/edges/faces are built up into meshes and surfaces, how matrices are formed as data structures, etc. Do you know whether anyone is using Pi3D and the book in a formal course? I'm going to see what it would take to expand what you've done into the kind of curricular material that's typically needed for it to meet regional accreditation requirements and be integrated with state standards for language and mathematics (Common Core Curriculum - CCC) and science (Next Generation Science Standards - NGSS). The accreditation makes it possible for courses to count for both high school and college/university credit. Taking such courses in HS is generally funded by school districts via taxes, instead of through college/university tuition and fees funded via scholarships, grants, loans, and individuals.
The best things in life aren't things ... but, a Pi comes pretty darned close!
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Pi3D

While I'm slogging through testing the demos on Windoze systems running Pi3D, there is another upcoming challenge I will need help to solve. I haven't seen any examples of how to texture map the inside of a sphere in Pi3D, and the reason I would like to do that is so that I can wrap the entire visible night sky around solar system entities, especially if it contained those stars beyond Earth-orbit parallax detection.

That would be instead of a random sub-chunk of night sky slathered on a plane stuck in the background, ala Earth.py (well, OK, that one rotates in a completely unnatural way, but, it's better than just the black of intergalactic space!).

Also, is it possible to use spherical texture maps larger than 1024x512 pixels? I seem to recall the answer was posted somewhere, but I'll be darned if I can find where I may have seen it.

Thanks and All the Best,
Jim
The best things in life aren't things ... but, a Pi comes pretty darned close!
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

Jim, sorry not to reply to your previous post. Lots of good ideas there - I was partly diverted because of some thoughts I had about making pi3d easier to set up on Windows and OSX by using an openGL wrapper such as SDL2. The main reason for not going down that route has been the speed impact on the RPi and it was a bit of a nightmare to compile (I understand, didn't try it myself). It's now a lot easier and can use the experimental GL driver. However in the process of looking at things I decided, as a kind of experiment, to re-write (some of) pi3d in rust. Yes, I know! There were various intermediate steps and jumps of logic - I will post something about the process elsewhere.

I'm not aware of anyone teaching from the book - it is quite tricky, more suitable for someone who can already program who wants to get into OpenGL. I think Peter Farrell (who put the videos on youtube) uses pi3d in classes sometimes.

There's a demo called EnvironmentSphere.py that shows how to use a 360x180 degree rectangular image mapped to the inside of a sphere. You can provide the same Texture to the shader and it will give the correct reflections of stars from the surface of your shiny rocket.

I think you can use larger images on the RPi. I think the widest it can cope with is 1920 but the height is probably limited by the GPU memory. Obviously there's not much advantage in having much higher resolution vertically than horizontally so 1920 x 960 is most likely candidate.

PS there is python file called RunDemos.py in pi3d_demos that can run a series of demos for a few seconds each. (It's what I use as a test suite) It has an optional extra argument for the name of the python you want it to use to run the demos, which I think I had to add when I used it on windows.

Gavinmc42
Posts: 4598
Joined: Wed Aug 28, 2013 3:31 am

Re: Pi3D

Been climbing the OpenGL learning curve since the Pi4 came out.
Trying examples in a few languages, most work

Then I remembered Pi3D.
It works quite fast on a Pi4 now, even in large windows.
It looks like Pi3D might be useful for learning without being annoyingly slow
Time to read the docs, book and every post here.

With the shader hardware now in the VC6, that's going to make it more fun, in a brain stretching way.
The shader language is C like, very clever indeed, but rather hard to fathom out.
No kidding, it's very weird looking at great graphics and the cpu's are barely working.

Perhaps start a new post "Pi3D on Pi4"?
But if is extended to a Rust version as well, where to post it?

Wow, Thonny is much better than Idle
I feel like i have gone full circle, back to Python on Pi's.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Posts: 2564
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3D

Yes python is quick and forgiving for just checking things out. Errors in GLSL code are quite hard to track down - often there's no error message at all! I've found that the the GL driver on the RPi4 is more of a stickler for the letter of the law than the equivalent on my laptop. So after getting the shader compiler to cope with specifying a display with ...gl_type="GLES", major=2, minor=0... etc, I have to completely refactor the code after I try it on the RPi. Actually I've only done that in the Rust version at the moment as it gives much more helpful error messages from faults in the shader code. I will port it over to python pi3d ASAP. So far as I can tell there is zero difference in execution speed for the same demo running as GL2.1 GLES2.0 or GLES3.0 but that's possibly because I haven't used any optimisations available in later versions.

I'm trying to keep the Rust version at least approximately similar in structure to python in case anyone want to migrate.

As well as coping with GLES3 shaders the next release will also have a Polygon (here's a filled one with a line round the edge)
polygon.jpg (11.51 KiB) Viewed 2267 times
And the full 3D model used to make the pi3d logo - rather than a cut-down ugly version
pi3dlogo128.png (26.34 KiB) Viewed 2267 times

Gavinmc42
Posts: 4598
Joined: Wed Aug 28, 2013 3:31 am

Re: Pi3D

Understanding the difference between VC4 and VC6 shaders is causing me trouble.
So I'm going to see if using Python for quick testing will help.
Water and clouds I nearly get, but procedural grass? Is it possible?

From the WebGL samples it should be , these work on a Pi4.
http://webglsamples.org/field/field.html
http://www.spacejack.ca/projects/terra/

Compiled or interpreted does not matter once it is compiled into the VC6 shaders.
Hmm, that means Lua should be able to do it too.
Yep , the Love2d guys have a bunch of shader effects.