3

I have this task to convert a 3D-object from a .obj-file (using Blender) into a 2D-picture using matplotlib in python. Converting from 3D to 2D is done using matrices, so thats ok, but I dont know how to get the coordinates from the file. When I print the file's content, I get this:

# Blender v2.73 (sub 0) OBJ File: ''
# www.blender.org
mtllib test.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 0.388735 1.108067 -2.206034
v 1.538758 0.520736 2.855389
v -0.570206 0.995216 0.054703
v -0.454593 3.815588 -1.404268
usemtl Material
s off

Can someone please help me? :)

Dambakk
  • 29
  • 4
  • You might be better off letting Blender do the interpretation of the .obj file format for you by just importing it in Blender, and writing an export script that iterates over the vertices. – Lukas Graf Mar 01 '15 at 14:05

1 Answers1

0

First create a list to store all your vertices. Each element of that list will itself be a list containing the x, y, and z coordinates as floating-point numbers.

Then read the .obj file line by line, splitting each line into a list. If the first element of that list is 'v', convert the next 3 strings in the list to float and store them into a new list. Then append that list to your list of vertices.

PM 2Ring
  • 54,345
  • 6
  • 82
  • 182