3Д БУМ

3Д принтеры и всё что с ними связано

CAUTION

Because the OBJ format can be unpredictable and also because it can be edited easily, it is helpful to have some error checking in place. For instance, the face structures may reference invalid vertices, such as vertex number -2, or a vertex number greater than the total number of vertices. To avoid problems later, you should incorporate some error checking into your code. Every time you load a value, be sure to check if it is valid. For instance, none of the numbers on the face line should be negative. Because they are indexes into an array, they must be positive or the program may crash. The same goes for values greater than the total number of vertices, texture coordinates, or normals. If a face references a vertex outside of what it should, the best option is to ignore that face completely. Doing this will probably result in a hole J in your model, but a small hole will look better than an ugly protrusion or artifact if you try to guess what the 4 index should be.

_______ I I______________________________ I I_____

This can cause unexpected results such as missing or deformed geom­etry, or even the model not showing up at all. If this happens, the easiest fix is to simply open the file and move the vertex information to the top of the file. However, for the purposes of learning and loading the most common OBJs, this should not be a problem.

When you get down to the face data, you simply take a look at the two variables and set your sscanf parameters appropriately.

Once you have all the data collected and stored, there are a few more things you should do before rendering. If you look closely at the class, you will notice that there are pointers for all of the types, as well as the resizable vectors. There is a very good reason for this.

The easiest way to access the elements of an STL vector is through the operator[] as you do with a standard array. However, this method can be quite slow and is not recommended, particularly if you need to use it each time you render a single frame, as is the case with the OBJ format.

The solution to this is to simply set the pointers to the first element in the STL vector. This does not cause a problem because STL vectors are

guaranteed to be continuous. This simple technique speeds the pro­gram up a lot.

Now that all of your data is organized, you can start worrying about rendering.

Для любых предложений по сайту: [email protected]