-2

So I tried running the code but it gives list out of index range error. I changed the index from 1 to 0, but the screen only pops up black. How could I change the code to make it work?

genpfault
  • 51,148
  • 11
  • 85
  • 139
ZDD
  • 9
  • 3
  • Please post the complete error message/stack trace. – skrx Oct 06 '17 at 16:31
  • obj = OBJ(sys.argv[1],"suzzane.mtl") IndexError: list index out of range I changed the index to 0 but then only a black screen pops up. – ZDD Oct 06 '17 at 16:50
  • Just copy everything you see under "Traceback (most recent call last):" and add that to your post. – skrx Oct 06 '17 at 16:56
  • It looks like you're instantiating `OBJ` incorrectly. The first argument should be the filename (I think the .obj file). The second argument is `swapyz` (should be a boolean). So if the filename is `suzzane.obj`, you should instantiate `OBJ` in this way: `obj = OBJ('suzzane.obj')`. – skrx Oct 06 '17 at 17:16
  • The script seems to be written in Python 2 and there are some things that have to be updated for Python 3, e.g. `v = list(map(float, values[1:4]))`. – skrx Oct 06 '17 at 17:19

2 Answers2

1

You just have to pass the filename/path of the .obj file to the OBJ class:

obj = OBJ('suzzane.obj')

Also, the script was written in Python 2 and if you want to use it with Python 3, you have to update a few things.

Change this line,

raise ValueError, "mtl file doesn't start with newmtl stmt"

to:

raise ValueError("mtl file doesn't start with newmtl stmt")

And all the map iterators have to be turned into lists:

mtl[values[0]] = map(float, values[1:])
# Just call `list()`.
mtl[values[0]] = list(map(float, values[1:]))
skrx
  • 19,980
  • 5
  • 34
  • 48
-1

Try generating wavefront(.obj) file and make sure to put the suzzane.obj and suzzane.mtl file on one directory with your code,

And instead of:

Sys.arg[0]

Use:

obj = OBJ('suzzane.obj')