I hope someone can help me with this problem.
I am using javafx and triangle mesh to construct a sphere-like object out of triangles (like a football). The different tiles of the shape are distinguished by color but I want to add lines between the tiles. Like in this football:
The provided 2D lines of javafx bring terrible performance in the 3D space. Therefore I found the FXyzLib that provides a PolyLine3D. This is actually just another triangle mesh that creates a line in a 3D space.
With this I can create 3D lines. But if I want to add them to my original triangle mesh everything else turns black. It is also the other way around. I experimented with the provided example of the Libary found here. It creats a fancy 3D line but when I tried to add a simple red colored sphere to the scene the sphere was just black like this:
.
I am no expert in this and new to javafx and couldn't find the problem in the code of the PolyLine3D. It shouldn't be a problem to add mutliple triangle mesh to a scene. Are there some light or camera effects I am not aware of?
While there is nothing wrong about adding multiple triangle meshes to a scene, there is a more straightforward approach when you want to create a mesh like one from the football picture, so you can have the effect of highlighting some edges but not all the triangles from the mesh.
It can be done with a
PolygonMesh
that takes any valid close polygon as face.This implementation already exists, in the 3DViewer project, which is open source and can be found here. There is a
PolygonMeshView
control that can render aPolygonMesh
.Note that if you use those two classes only in your project, you'll have to skip the subdivision mesh for now.
This answer already uses a quadrilateral mesh for a rendering a Box without the diagonal edges of a triangle mesh.
Under the hood, the Polygon mesh uses a triangle mesh, and internally converts the polygons you provide to triangles.
Truncated Icosahedron Mesh
So we can do something similar to generate the mesh of a truncated icosahedron, which is the name of the geometric figure that we can use to generate a simplified football model.
It has 12 regular pentagonal faces, 20 regular hexagonal faces and 60 vertices.
We need the 3D coordinates of those vertices, the 2D coordinates of the textures, and the indices of vertices and textures for each of the 32 faces.
I've used the free online sandbox WolframCloud resource to retrieve those values.
For instance, you can run:
to get the list of vertex coordinates:
and, you can get the faces:
Finally, you need the textures coordinates and indices, and that can be retrieved through the Net of the icosahedron:
In this case, you get the 2D coordinates of the 32 faces. Given that we want to have the same texture for all the pentagons and the same for all hexagons, I've dome some manipulation of those coordinates to come up with this texture image:
with only 9 vertices, and their coordinates (in the JavaFX coordinate system).
This method contains the required information to create the mesh:
Now you can easily add it to an scene:
Will give you the wireframe:
And if you add the image of the texture, you will get your football:
Now it's up to you to manipulate to your convenience this information, and modify this mesh into the one you are looking for.