OBJ to Indexed face set
OBJ files store data representing 3d objects.
Several objects can be defined in an OBJ file by separating them with lines starting with o followed by the name of the object:
o geometric_object
If only one object is described by the OBJ file this line is not mandatory. For each object vertex coordinates and possibly texture and normal coordinates are given in the following way:
v x y z [w] # The list of coordinate values of each vertex.
vt x [y z] # The list of texture coordinates which can vary between 0 and 1. y and z are optional.
vn x y z # The list of vertex normals.
Depending on the previous input the face values are given as follows:
f 1 2 3 # no vt and vn given
f 1/1 2/1 3/1 # vt but no vn given
f 1//1 2//1 3//1 # vn but no vt given
f 1/6/7 2/6/7 3/6/7 # both, vn and vt given where the middle number stands for the vt index
Note
vt and vn attributes belong to pairs of the form (vertex, face). Such pairs can’t be handled by IndexedFaceSet.
If vt and vn are given in the OBJ file, these attributes are ignored.
For converting objects given in a OBJ file use obj_to_ifs().
If the OBJ data is located in the file “surface.obj”, the IFS surface can be simply created by:
>>> from ddg.conversion.indexedfaceset.obj import obj_to_ifs
>>> file = "path-to-file/surface.obj"
>>> surface = obj_to_ifs(file)
If there are multiple objects in the OBJ file, the output is a dictionary, whose keys are the object names. If only one object
is in the obj file, the corresponding IFS object is returned directly.
Note
In an OBJ file vertex indices start at 1. In the IFS datastructure vertex indices start at 0. Thus the vertex indices of the resulting IFS object are given with an offset of -1.