I need to voxelize triangle meshes which involves testing if a point is located inside or outside the given mesh. I have just implemented a basic algo based on raycasting and checking the number of ray-mesh intersections (by intersecting the ray with each triangle).
I select a position which lies outside the mesh: I add a small offset to the mesh's bounding box. Then I cast a ray from the point being tested to the position calculated above.
1) How to find the position which definitely lies inside or outside the mesh? What are good values for the 'offset' which is added to the mesh's bounds? (Currently, I'm using offset = vec3(1,1,1).)
2) The method is very slow. For example, voxelizing "cow.ply" (17412 vertices, 5804 triangles) on a 128^3 grid takes almost 5 minutes on a 3 GHz CPU! What is a good acceleration strategy? (I plan to add a uniform grid where each cell keeps indices to intersecting triangles.)