' '

1. Implementation

Your ray tracer comes with code that is able to read mesh files. However, it does not translate the file data into an actual Primitive: you still need to write code yourself that creates the necessary Triangles and BoundingBoxAccelerators.

Create files primitives/mesh/mesh-primitive.cpp and primitives/mesh/mesh-primitive.h. Implement a factory function in the raytracer::primitives namespace:

Primitive mesh(const std::string& path);
Tip

You will want to write a MeshReceiver subclass that collects all data from the file and builds a hierarchy.

Note

No mesh optimization needs to be done here. Simply read in the file and recreate the exact same hierarchy.

Important

Make sure to check that the file opened successfully. If the file failed to open, you will still be able to read data from it, but this data will be garbage.

2. Evaluation

Recreate this scene using a mesh:

You will have to manually create a mesh file to represent this pyramid.

Show that if given a wrong path, this error is caught and a message Failed to open file at <path> is shown in the logs. You can use the CHECK macro for this.