{"id":80,"date":"2013-11-08T15:46:23","date_gmt":"2013-11-08T15:46:23","guid":{"rendered":"\/\/3dbym.ru\/2013\/11\/caution\/"},"modified":"2013-11-08T15:46:23","modified_gmt":"2013-11-08T15:46:23","slug":"caution","status":"publish","type":"post","link":"https:\/\/3dbym.ru\/2013\/11\/caution\/","title":{"rendered":"CAUTION"},"content":{"rendered":"

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.<\/p>\n

_______ I I______________________________ I I_____<\/p>\n

This can cause unexpected results such as missing or deformed geom\u00adetry, 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.<\/p>\n

When you get down to the face data, you simply take a look at the two variables and set your sscanf parameters appropriately.<\/p>\n

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.<\/p>\n

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.<\/p>\n

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<\/p>\n

<\/p>\n

guaranteed to be continuous. This simple technique speeds the pro\u00adgram up a lot.<\/p>\n

Now that all of your data is organized, you can start worrying about rendering.<\/p>\n","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts\/80"}],"collection":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":0,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"wp:attachment":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}