StanfordVL / 3DSceneGraph

The data skeleton from "3D Scene Graph: A Structure for Unified Semantics, 3D Space, and Camera" http://3dscenegraph.stanford.edu
Other
240 stars 31 forks source link

Exporting semantic .obj as a standard wavefront .obj format #4

Closed zubair-irshad closed 4 years ago

zubair-irshad commented 4 years ago

Hi, I have a query regarding integrating exported semantic .obj/.mtl files with Gibson Env for on the fly computation of 2D scene graph:

The current load.py script exports semantic .obj in the following non-standard wavefront format:

# List of geometric vertices, with (x, y, z [,w]) coordinates, w is optional and defaults to 1.0.
  v 0.123 0.234 0.345 1.0
  v ...
  ...
mtllib usemtl ...
  # Polygonal face element (see below)
  f 1 2 3
  f ...
  ...

The above format is inconsistent with standard wavefront OBJ laoder provided with Gibson Environment. How can I generate and save semantic .obj files in the standard wavefront format described below:

  # List of geometric vertices, with (x, y, z [,w]) coordinates, w is optional and defaults to 1.0.
  v 0.123 0.234 0.345 1.0
  v ...
  ...
  # List of texture coordinates, in (u, [,v ,w]) coordinates, these will vary between 0 and 1. v, w are optional and default to 0.
  vt 0.500 1 [0]
  vt ...
  ...
  # List of vertex normals in (x,y,z) form; normals might not be unit vectors.
  vn 0.707 0.000 0.707
  vn ...
  ...
mtllib usemtl ...

  # Polygonal face element (see below)
  f 6/4/1 3/5/3 7/6/5
  f ...
  ...

Thanks in advance for the help!

zubair-irshad commented 4 years ago

I was able to resolve the issue by adding the following lines of code:

To save surface normal:

vn_ = 'vn '

vn_ += trimesh.util.array_to_string(mesh.vertex_normals,col_delim=' ',row_delim='\nvn ',digits=8) + '\n'

file.write(vn_)

face_type.append('vn')

To save face vertices/normals:

faces = 'f ' + trimesh.util.array_to_string(mesh.faces[layer_type[layer].inst_segmentation,:] + 1, col_delim=' ', row_delim='\nf ', value_format=face_format)

file.write(faces)

Hence, I am closing this issue.