Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will want to iterate over the obj data looking for 'v's and checking if the following x y and z coordinates and recording the highest and lowest value each time you encounter it. The following code prints out the highest and lowest value for each dimension and then gives you the bounding box from that</p> <pre><code>obj = 'v -5 -5 0 v -5 -5 5 v 0 -5 0 v 0 -5 5 vt 0 0 vt 0 1 vt 1 0 vt 1 1 vn 0 -1 0 vn 0 -1 0 vn 0 -1 0 vn 0 -1 0 f 4/4/4 2/2/2 1/1/1 3/3/3 v 0 -5 0 v 0 -5 5 v 0 0 0 v 0 0 5 vt 0 0 vt 0 1 vt 1 0 vt 1 1 vn 1 0 0 vn 1 0 0 vn 1 0 0 vn 1 0 0 f 8/8/8 6/6/6 5/5/5 7/7/7 v 0 0 0 v 0 0 5 v -5 0 0 v -5 0 5 vt 0 0 vt 0 1 vt 1 0 vt 1 1 vn 0 1 0 vn 0 1 0 vn 0 1 0 vn 0 1 0 f 12/12/12 10/10/10 9/9/9 11/11/11 v -5 0 0 v -5 0 5 v -5 -5 0 v -5 -5 5 vt 0 0 vt 0 1 vt 1 0 vt 1 1 vn -1 0 0 vn -1 0 0 vn -1 0 0 vn -1 0 0 f 16/16/16 14/14/14 13/13/13 15/15/15 v -5 -5 0 v 0 -5 0 v -5 0 0 v 0 0 0 vt 0 0 vt 0 1 vt 1 0 vt 1 1 vn 0 0 -1 vn 0 0 -1 vn 0 0 -1 vn 0 0 -1 f 20/20/20 18/18/18 17/17/17 19/19/19 v -5 -5 5 v -5 0 5 v 0 -5 5 v 0 0 5 vt 0 0 vt 0 1 vt 1 0 vt 1 1 vn 0 0 1 vn 0 0 1 vn 0 0 1 vn 0 0 1 f 24/24/24 22/22/22 21/21/21 23/23/23' elements = obj.split(' ') x_min = 0.0 x_max = 0.0 y_min = 0.0 y_max = 0.0 z_min = 0.0 z_max = 0.0 i = 0 while i &lt; len(elements): if elements[i] == 'v': #find min and max x value if float(elements[i + 1]) &lt; x_min: x_min = float(elements[i + 1]) elif float(elements[i + 1]) &gt; x_max: x_max = float(elements[i + 1]) #find min and max y value if float(elements[i + 2]) &lt; y_min: y_min = float(elements[i + 2]) elif float(elements[i + 2]) &gt; y_max: y_max = float(elements[i + 2]) #find min and max x value if float(elements[i + 3]) &lt; z_min: z_min = float(elements[i + 3]) elif float(elements[i + 3]) &gt; z_max: z_max = float(elements[i + 3]) #incriment the counter int by 4 as we know the next 4 elements are not a vertex i += 4 else: i += 1 print 'x_min = ' + str(x_min) print 'x_max = ' + str(x_max) print 'y_min = ' + str(y_min) print 'y_max = ' + str(y_max) print 'z_min = ' + str(z_min) print 'z_max = ' + str(z_max) print '' print 'x_widh = ' + (str(x_max - x_min)) print 'y_widh = ' + (str(y_max - y_min)) print 'z_widh = ' + (str(z_max - z_min)) </code></pre> <p>And heres the output i get</p> <pre><code>x_min = -5.0 x_max = 0.0 y_min = -5.0 y_max = 0.0 z_min = 0.0 z_max = 5.0 x_widh = 5.0 y_widh = 5.0 z_widh = 5.0 </code></pre> <p>Hope that makes sense</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload