Closed HybridDog closed 2 years ago
My implementation uses simple vector math. A triangle can be seen as a 2d subspace of the vector space. We therefore have two basis vectors b1 and b2 (the sides of the triangle). Now we can iterate the subspace so that we get points on the triangle being x b1 + y b2 with x+y <= 1
I have recently implemented the vector.triangle function in vector_extras. It converts a triangle defined by three (not necessarily integer) positions to a list of integer Minetest positions and returns the corresponding barycentric coordinates (they may be a bit inaccurate because the integer position is not (yet) projected back to the triangle plane). As far as I can see, voxelizer uses a different way to voxelize a triangle. I don't know which way works better; you can try vector.triangle if you want.
My implementation had the problem that holes appear between neighbouring triangles and I don't know if I fixed it correctly. Here's a sphere approximated with triangles, where holes can be seen (happens when eps is 0):