As the title says, how would I write an algorithm to convert a OBJ face to triangles?
Example: You have a cube.obj file that has 6 faces, but they have 4 vertexes (Per face), and you can only render in 3D triangles. How would you convert the data to a set of points and lines defined as the points to connect?
Here's my .love file in case it's relevant
(BTW, the rendered shape when you execute the .love file is only getting the vertex positions, the lines are predefined so it actually renders)
How would I write an algorithm to convert a OBJ face to triangles?
-
- Prole
- Posts: 16
- Joined: Thu May 27, 2021 12:32 am
How would I write an algorithm to convert a OBJ face to triangles?
"There is no such thing as a mistake, only happy accidents"
Re: How would I write an algorithm to convert a OBJ face to triangles?
Some general pointers, may or may not apply to your problem:
A quad on a plane is trivially converted to two triangles
{ 0, 1, 3 } is triangle #1, and { 1, 2, 3 } is triangle #2. In your cube example you would ideally represent this as an indexed triangle list, to keep the number of vertices low.
Any convex polygon on a plane is easily triangulated using fanning: insert a vertex at center of polygon, then go around counter-clockwise and connect vertices to center vertex.
There's also love.math.triangulate that you could use for more complex cases, but that has its limitations.
The best and common solution is to only export triangulated meshes so you don't have to deal with triangulation yourself. Every 3D modeling software that exports OBJ has this option.
A quad on a plane is trivially converted to two triangles
Code: Select all
0---3
| |
1---2
Any convex polygon on a plane is easily triangulated using fanning: insert a vertex at center of polygon, then go around counter-clockwise and connect vertices to center vertex.
There's also love.math.triangulate that you could use for more complex cases, but that has its limitations.
The best and common solution is to only export triangulated meshes so you don't have to deal with triangulation yourself. Every 3D modeling software that exports OBJ has this option.
-
- Prole
- Posts: 16
- Joined: Thu May 27, 2021 12:32 am
Re: How would I write an algorithm to convert a OBJ face to triangles?
Ah. I'll search for the option on my modeling software I guess.grump wrote: ↑Tue Jun 29, 2021 9:04 am Some general pointers, may or may not apply to your problem:
A quad on a plane is trivially converted to two triangles{ 0, 1, 3 } is triangle #1, and { 1, 2, 3 } is triangle #2. In your cube example you would ideally represent this as an indexed triangle list, to keep the number of vertices low.Code: Select all
0---3 | | 1---2
Any convex polygon on a plane is easily triangulated using fanning: insert a vertex at center of polygon, then go around counter-clockwise and connect vertices to center vertex.
There's also love.math.triangulate that you could use for more complex cases, but that has its limitations.
The best and common solution is to only export triangulated meshes so you don't have to deal with triangulation yourself. Every 3D modeling software that exports OBJ has this option.
"There is no such thing as a mistake, only happy accidents"
Re: How would I write an algorithm to convert a OBJ face to triangles?
blender: Edit mode --> Select faces and Ctrl+T to triangulate it.ThatCodingGuy78 wrote: ↑Tue Jun 29, 2021 9:11 am Ah. I'll search for the option on my modeling software I guess.
https://docs.blender.org/manual/en/late ... faces.html
-
- Prole
- Posts: 16
- Joined: Thu May 27, 2021 12:32 am
Re: How would I write an algorithm to convert a OBJ face to triangles?
Thanks!darkfrei wrote: ↑Tue Jun 29, 2021 10:28 amblender: Edit mode --> Select faces and Ctrl+T to triangulate it.ThatCodingGuy78 wrote: ↑Tue Jun 29, 2021 9:11 am Ah. I'll search for the option on my modeling software I guess.
https://docs.blender.org/manual/en/late ... faces.html
"There is no such thing as a mistake, only happy accidents"
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 2 guests