|
Post by ascotti on Jan 2, 2019 10:16:33 GMT
One of the less exciting thing about .obj files is they come in all sort of size and position, driving you crazy with transformations. I've eventually implemented a normalization function for them and it has since saved me tons of time and headaches. It is very simple and works on the vertex array _before_ triangles are actually built: bbox = bounding_box( all vertices ) sx = bbox.max.x - bbox.min.x sy = bbox.max.y - bbox.min.y sz = bbox.max.z - bbox.min.z scale = max(sx, sy, sz) / 2 for each vertex v v.x = (v.x - (bbox.min.x + sx/2)) / scale v.y = (v.y - (bbox.min.y + sy/2)) / scale v.z = (v.z - (bbox.min.z + sz/2)) / scale
And that's it. Now the object is inside a box that goes from (-1,-1,-1) to (+1,+1,+1) i.e. like a standard cube or sphere, making it much easier to work with. Here's an example. (Info: it was rendered at 4x the size posted, then scaled down to remove some aliasing due to some very small triangles... there are about 97K in this model! It took about 17 minutes to render.)
|
|
|
Post by sbehnke on Jul 8, 2019 4:48:15 GMT
This is amazingly helpful! I will add it to mine tomorrow.
|
|