Skip to content

Commit

Permalink
Merge pull request hiroharu-kato#9 from czw0078/master
Browse files Browse the repository at this point in the history
Add support for // when loading obj files.
  • Loading branch information
nkolot authored Aug 7, 2018
2 parents a7425f2 + 06ea5cf commit 29a7615
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions neural_renderer/load_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ def load_textures(filename_obj, filename_mtl, texture_size):
if line.split()[0] == 'f':
vs = line.split()[1:]
nv = len(vs)
if '/' in vs[0]:
if '/' in vs[0] and '//' not in vs[0]:
v0 = int(vs[0].split('/')[1])
else:
v0 = 0
for i in range(nv - 2):
if '/' in vs[i + 1]:
if '/' in vs[i + 1] and '//' not in vs[i + 1]:
v1 = int(vs[i + 1].split('/')[1])
else:
v1 = 0
if '/' in vs[i + 2]:
if '/' in vs[i + 2] and '//' not in vs[i + 2]:
v2 = int(vs[i + 2].split('/')[1])
else:
v2 = 0
Expand Down Expand Up @@ -85,6 +85,14 @@ def load_textures(filename_obj, filename_mtl, texture_size):
for material_name, filename_texture in texture_filenames.items():
filename_texture = os.path.join(os.path.dirname(filename_obj), filename_texture)
image = imread(filename_texture).astype(np.float32) / 255.

# texture image may have one channel (grey color)
if len(image.shape) == 2:
image = np.stack((image,)*3,-1)
# or has extral alpha channel shoule ignore for now
if image.shape[2] == 4:
image = image[:,:,:3]

# pytorch does not support negative slicing for the moment
image = image[::-1, :, :]
image = torch.from_numpy(image.copy()).cuda()
Expand Down

0 comments on commit 29a7615

Please sign in to comment.