This is my answer to Frank Luna’s “Introduction to 3D Game Programming with Direct X 12”, Chapter 6 “Drawing in Direct3D”, Exercise 16: “On the DVD, there a file called Models/Skull.txt. This file contains the vertex and index lists needed to render the skull in Figure 7.11. Study the file using a text editor like notepad, and modify the “Shapes” demo to load and render the skull mesh”
Well in the next chapter “Lighting” Frank renders the skull anyway, so its not too difficult to find a solution if you get stuck. Follow the process for creating the vertex and index buffers as Frank does for the other meshes. I created more of a generic function, whereas the app provided in the book is very specific, this however makes my solution suitable for creating a second mesh, which I have named “SkullGeo” whereas the primitives already in the scene are submeshes (the parent mesh he calls “ShapesGeo”), all which share the same index and vertex buffer and simply provide an offset to their region of these global buffers. But having a new parent mesh for the skull is what he does in the next chapter anyway.
Take in mind the input file contains normals for lighting, which we don’t want now, so I have added extra “ignores” when parsing the file.
If you were writing a real engine I would have objects derived from an interface generalised to any input type, making different readers “pluggable”. Obviously the solution here is specific to the provided input file.
Once you have read all of this data you must create the render item, I again made a generic function to cut down on boilerplate. Don’t forget to add a unique constant buffer number for the shader (the skull item is at the bottom of the next excerpt).