Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically you could create something like a <code>class OBJModel</code> and then have a <code>OBJModelLoader.load(final InputStream is);</code> which loads the <em>wavefront .obj file</em> and returns an instance of the <code>class OBJModel</code>.</p> <p>Within the <code>class OBJModel</code>, you would have some array storing vertices, normals, texture coordinates, faces, materials, etc.</p> <h1>Loading The Model</h1> <p>If you don't know what all those things inside the <em>.obj</em> file means, then you can read all about it on <a href="http://en.wikipedia.org/wiki/Wavefront_.obj_file" rel="nofollow">Wikipedia click here</a></p> <p>Just to give an idea how you would make the <code>OBJModel load()</code> method, here is an idea:</p> <pre><code>public final static OBJModel load(final InputStream is) { final OBJModel model = new OBJModel(); try (final BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String line; while ((line = br.readLine()) != null) { if (line.isEmpty() || (line.charAt(0) == '#')) { continue; } if (line.contains("#")) { line = line.substring(0, line.indexOf('#')); } line = line.trim(); if (line.isEmpty()) { continue; } if (line.startsWith("v ")) { String[] xyz = line.split(" "); float x = Float.parseFloat(xyz[1]); float y = Float.parseFloat(xyz[2]); float z = Float.parseFloat(xyz[3]); model.addVertex(x, y, z); continue; } else if (line.startsWith("vn ")) { String[] xyz = line.split(" "); float x = Float.parseFloat(xyz[1]); float y = Float.parseFloat(xyz[2]); float z = Float.parseFloat(xyz[3]); model.addNormal(x, y, z); continue; } else if (line.startsWith("vt ")) { String[] uv = line.split(" "); float u = Float.parseFloat(uv[1]); float v = Float.parseFloat(uv[2]); model.addTextureCoordinate(u, v); continue; } else if (line.startsWith("f ")) { </code></pre> <p>As I only made this to give you an idea of how to make it you would have to complete it yourself.</p> <h1>Rendering The Model</h1> <p>When you want to render the model, well just do as you would do regularly when you would render vertices with texture coordinates.</p> <p>Blender supplies with all the correct texture coordinates, so the only thing you need to do is bind the texture before you render all the vertices with their texture coordinates.</p> <p>I will recommend using <code>VAOs</code> for storing and rendering the model, though it depends on the version of OpenGL you're using. If you can't use <code>VAOs</code> then just use regular <code>VBOs</code> using the <code>gl*Pointer</code> calls, but don't use immediate mode for rendering.</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.
    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