Exemple #1
0
    def write(self, mesh):
        '''
        Write a mesh to an obj file.
        Assumes mesh vertices, faces, and normals are in standard python list objects.
        Does not support material files or texture coordinates
        '''
        f = open(self.filepath_, 'w')
        vertices = mesh.vertices()
        faces = mesh.triangles()
        normals = mesh.normals()

        # write human-readable header
        f.write('###########################################################\n')
        f.write('# OBJ file generated by UC Berkeley Automation Sciences Lab\n')
        f.write('#\n')
        f.write('# Num Vertices: %d\n' %(len(vertices)))
        f.write('# Num Triangles: %d\n' %(len(faces)))
        f.write('#\n')
        f.write('###########################################################\n')
        f.write('\n')

        # write the vertex list
        for v in vertices:
            f.write('v %f %f %f\n' %(v[0], v[1], v[2]))

        # write the normals list
        if normals is not None and len(normals) > 0:
            for n in normals:
                f.write('vn %f %f %f\n' %(n[0], n[1], n[2]))

        # write the normals list
        for t in faces:
            f.write('f %d %d %d\n' %(t[0]+1, t[1]+1, t[2]+1)) # convert back to 1-indexing

        f.close()
Exemple #2
0
 def write_mesh_3d(mesh, data):
     """ Writes mesh object to HDF5 data provided in |data| """
     data.create_dataset(MESH_VERTICES_KEY, data=np.array(mesh.vertices()))
     data.create_dataset(MESH_TRIANGLES_KEY,
                         data=np.array(mesh.triangles()))
     if mesh.normals() is not None:
         data.create_dataset(MESH_NORMALS_KEY,
                             data=np.array(mesh.normals()))
Exemple #3
0
    def write(self, mesh):
        '''
        Write a mesh to an obj file.
        Assumes mesh vertices, faces, and normals are in standard python list objects.
        Does not support material files or texture coordinates
        '''
        f = open(self.filepath_, 'w')
        vertices = mesh.vertices()
        faces = mesh.triangles()
        normals = mesh.normals()
        colors = mesh.colors()

        # write human-readable header
        f.write(
            '###########################################################\n')
        f.write(
            '# OBJ file generated by UC Berkeley Automation Sciences Lab\n')
        f.write('#\n')
        f.write('# Num Vertices: %d\n' % (len(vertices)))
        f.write('# Num Triangles: %d\n' % (len(faces)))
        f.write('#\n')
        f.write(
            '###########################################################\n')
        f.write('\n')

        if colors is None:
            # write the vertex list
            for v in vertices:
                f.write('v %f %f %f\n' % (v[0], v[1], v[2]))
        else:
            assert len(vertices) == colors.shape[0], 'Color dimension mismatch'
            for v, c in zip(vertices, colors):
                f.write('v %f %f %f %f %f %f\n' %
                        (v[0], v[1], v[2], c[0], c[1], c[2]))

        # write the normals list
        if normals is not None and len(normals) > 0:
            for n in normals:
                f.write('vn %f %f %f\n' % (n[0], n[1], n[2]))

        # write the normals list
        for t in faces:
            f.write(
                'f %d %d %d\n' %
                (t[0] + 1, t[1] + 1, t[2] + 1))  # convert back to 1-indexing

        f.close()

        logging.info('Wrote mesh to %s', self.filepath_)
Exemple #4
0
    def write(self, mesh):
        '''
        Write a mesh to an obj file.
        Assumes mesh vertices, faces, and normals are in standard python list objects.
        Does not support material files or texture coordinates
        '''
        f = open(self.filepath_, 'w')
        vertices = mesh.vertices()
        faces = mesh.triangles()
        normals = mesh.normals()
        colors = mesh.colors()

        # write human-readable header
        f.write('###########################################################\n')
        f.write('# OBJ file generated by UC Berkeley Automation Sciences Lab\n')
        f.write('#\n')
        f.write('# Num Vertices: %d\n' %(len(vertices)))
        f.write('# Num Triangles: %d\n' %(len(faces)))
        f.write('#\n')
        f.write('###########################################################\n')
        f.write('\n')

        if colors is None:
            # write the vertex list
            for v in vertices:
                f.write('v %f %f %f\n' %(v[0], v[1], v[2]))
        else:
            assert len(vertices) == colors.shape[0], 'Color dimension mismatch'
            for v, c in zip(vertices, colors):
                f.write('v %f %f %f %f %f %f\n' %(v[0], v[1], v[2], c[0], c[1], c[2]))

        # write the normals list
        if normals is not None and len(normals) > 0:
            for n in normals:
                f.write('vn %f %f %f\n' %(n[0], n[1], n[2]))

        # write the normals list
        for t in faces:
            f.write('f %d %d %d\n' %(t[0]+1, t[1]+1, t[2]+1)) # convert back to 1-indexing

        f.close()

        logging.info('Wrote mesh to %s', self.filepath_)
Exemple #5
0
    def write(self, mesh):
        '''
        Write a mesh to an obj file.
        Assumes mesh vertices, faces, and normals are in standard python list objects.
        Does not support material files or texture coordinates
        '''
        f = open(self.filepath_, 'w')
        vertices = mesh.vertices()
        faces = mesh.triangles()
        normals = mesh.normals()

        # write human-readable header
        f.write(
            '###########################################################\n')
        f.write(
            '# OBJ file generated by UC Berkeley Automation Sciences Lab\n')
        f.write('#\n')
        f.write('# Num Vertices: %d\n' % (len(vertices)))
        f.write('# Num Triangles: %d\n' % (len(faces)))
        f.write('#\n')
        f.write(
            '###########################################################\n')
        f.write('\n')

        # write the vertex list
        for v in vertices:
            f.write('v %f %f %f\n' % (v[0], v[1], v[2]))

        # write the normals list
        if normals is not None and len(normals) > 0:
            for n in normals:
                f.write('vn %f %f %f\n' % (n[0], n[1], n[2]))

        # write the normals list
        for t in faces:
            f.write(
                'f %d %d %d\n' %
                (t[0] + 1, t[1] + 1, t[2] + 1))  # convert back to 1-indexing

        f.close()