OpenPolyhedra  1.0
Open Polyhedra - set texture coordinates to polyhedra.

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.
1. 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.
1. 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:
1. Sort the intersections along the ray (parametrically described).
2. The one closer to the origin of the ray is from the selected face.
3. If the polyhedra are convex, there can be only two intersections.
4. The ray has coordinates (x,y,0) and (x,y,1).
5. Use gluUnProject to bring the ray back to world coordinates.
6. 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.
1. Remember that the fixed point of a linear transformation is the origin.
2. Therefore, choose the edge that will work as a rotation axis, and translate one of its two vertices, to the origin.
3. 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...

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):

1. sudo dnf install python2-pyopengl python2-pillow
• or
1. sudo dnf install python3-pyopengl python3-pillow
1. sudo apt-get install python-opengl python-pil
• or
1. sudo apt-get install python3-opengl python3-pil
1. sudo port install py27-opengl py27-Pillow
• or
1. sudo port install py36-opengl py36-Pillow

To run the program:

1. model_name is the OFF file to be read.
2. texture_name is the initial image to be used as texture.
3. -t switches between using the Idle callback function or _timer function.
4. -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
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:

1. the first line contains the word OFF,
2. the second line is optional, and tells whether vertex indices start at 0 or 1,
3. and the third line, indicates the number of vertices and faces (polygons).
4. 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

Dodecahedron
Flattened
Projected
Textured
Dolphin
Flattened
Projected
Textured

Dodecahedron

Unfolded

Projected

Textured

Dolphin

Flattened

Projected

Textured