This program sets texture coordinates to vertices of the Platonic solids (perfect polyhedra): tetrahedron, octahedron, hexahedron (cube), icosahedron and dodecahedron.
Platonic Solids
Main Steps:
- A face of the polyhedron must be selected with the mouse, so all the other faces become coplanar with the selected face.
- Then, it is just a question of mapping the open (flattened) polyhedron onto the texture plane (z=0).
- The faces can be traversed in any order, without repetition.
- Modeling polyhedra as graphs, one can use any traversal algorithm, e.g., breadth or depth first.
- The mapping corresponds to a change of basis: uvn -> xy(z=0), where n is the normal vector of the selected face, and u and v, two vectors on the face plane (pag. 109).
- To select (pick) a face, shoot a ray from the mouse position, and intersect it against the faces of the polyhedron:
- Sort the intersections along the ray (parametrically described).
- The one closer to the origin of the ray is from the selected face.
- If the polyhedra are convex, there can be only two intersections.
- The ray has coordinates (x,y,0) and (x,y,1).
- Use gluUnProject to bring the ray back to world coordinates.
- It is necessary an algorithm of point in polygon testing (an implementation using winding number is simpler, but one using the even-odd rule is more robust).
- Each polygon must contain the transformation with all rotations accumulated, along the path from the selected face, until reaching it.
- Remember that the fixed point of a linear transformation is the origin.
- Therefore, choose the edge that will work as a rotation axis, and translate one of its two vertices, to the origin.
- Then, apply the rotation and translate it back.
- The transformation of the selected (initial) face is the identity.
- The fifth element, dodecahedron, is not Mila Jovovich.
Take a look at drawTexture() for further theoretical reasoning...
- See also
- https://en.wikipedia.org/wiki/Platonic_solid
-
https://en.wikipedia.org/wiki/Archimedean_solid
release.notes
This is a python program. Therefore, it is necessary to have python installed.
- It should run either using python 2 or python 3, on Linux, and MacOs.
There are some additional packages needed, such as PyOpenGL and PIL (Python Imaging Library):
- sudo dnf install python2-pyopengl python2-pillow
- sudo dnf install python3-pyopengl python3-pillow
- sudo apt-get install python-opengl python-pil
- sudo apt-get install python3-opengl python3-pil
- sudo port install py27-opengl py27-Pillow
- sudo port install py36-opengl py36-Pillow
To run the program:
- model_name is the OFF file to be read.
- texture_name is the initial image to be used as texture.
- -t switches between using the Idle callback function or _timer function.
- -v turns on the verbose mode.
It is assumed that:
- some texture files are available in a directory called "images",
- and the models, in format OFF, are available in a directory called "models",
at the same level from where openPolyhedron.py is executed.
In Python, __debug__ is a constant used to determine if calls to assert should result in code being generated.
- If you have the -O optimization flag set, then assert calls will not be “triggered” in your code, even if the condition it is testing is true.
- python -O openPolyhedron.py -m cube.off
- See also
- https://ironboundsoftware.com/blog/2017/01/09/python-__debug__/
-
https://stackoverflow.com/questions/1693088/what-is-the-use-of-pythons-basic-optimizations-mode-python-o
The OFF format is basically PLY without the header:
- the first line contains the word OFF,
- the second line is optional, and tells whether vertex indices start at 0 or 1,
- and the third line, indicates the number of vertices and faces (polygons).
- OFF example for a cube:
OFF
0
8 6
1.0 1.0 1.0
-1.0 1.0 1.0
-1.0 -1.0 1.0
1.0 -1.0 1.0
1.0 1.0 -1.0
-1.0 1.0 -1.0
-1.0 -1.0 -1.0
1.0 -1.0 -1.0
4 5 1 0 4
4 4 7 6 5
4 4 0 3 7
4 2 6 7 3
4 0 1 2 3
4 1 5 6 2
- Todo:
[graphical interface, read PLY directly]
Qt4 or Qt5 based
PLY reader, writer
Screen Shots
Dodecahedron
Flattened
Projected
Textured
Dolphin
Flattened
Projected
Textured
Dodecahedron
Unfolded
Projected
Textured
Dolphin
Flattened
Projected
Textured