Although we entered the true 3D world, but the previous chapter of the demo is still shown a plane, although our plane in 3D space rotation can see a little 3D perspective effect, but since it is true 3D, it is necessary to take out a dot 3D look!
If we're going to show the three-dimensional model, we're going to say goodbye to the time of writing vertex data directly with the code, think of the last section, the plane's quadrilateral handwritten vertices may be passable, but it's a bit hard to write 8 vertex data for a cube, if it's a more complex shape?
To display a 3D model, you need a 3D model file in a specific format, 3D model files are generally created with the 3D modeling tool, and the model is exported to a 3D model data file in a specific format after the completion of the artwork, with the common format of obj, MD2, MD5, and Daes, Of course more cases are custom binary formats (smaller size parsing is faster, but sacrificing readability and versatility).
For a particular format of a file, we need to write a specific parsing class to parse, parsing the data in the file into the vertex data that we can use directly.
We use the Objparser class, which is provided in the book to parse the obj data file, and use this class to obtain data such as the vertex position, Uvs, and so on, which are defined in the file directly after parsing the obj file.
Objparser class
After getting the data in the model file, it can be drawn to the 3D stage, the drawing method and the previous section have been, the following directly on the demo:
Code
"Stage3D Learning Notes continued" Real 3D World (ii): Display model