Hi,
I'm trying to load normals in but am having trouble the problem is is the vertices load in fine but when I try to load the vn for the obj file I get really weird results any help would be appreciated [code] public void loadModel() { String fileName = "C://Documents and Settings//Administrator//Desktop//open//3DGameDesign//src//Box//Normal.obj"; File aFile = new File( fileName ); BufferedReader aReader = null; try { String currentLine; aReader = new BufferedReader( new FileReader( aFile ) ); currentLine = aReader.readLine(); while( currentLine != null ) { if( currentLine.startsWith( "v ") ) { String vNames = currentLine.replaceAll( "v ", "" ); String[]vVertex = vNames.split( " " ); for( int i = 0; i < vVertex.length; i++ ) { vVerts.add( vVertex[ i ] ); } } if( currentLine.startsWith( "vn " ) ) { String nNames = currentLine.replaceAll("vn ", "" ); String[]nVertex = nNames.split( " " ); for( int i = 0; i < nVertex.length; i++ ) { nVerts.add( nVertex[ i ] ); } } currentLine = aReader.readLine(); } } catch( IOException ioe ) { System.out.println( "Cannot Load Model: " + ioe ); } finally { try { aReader.close(); } catch( Exception e ) { System.out.println( "Cannot Close File: " + e ); } } } @Override public void display(GLAutoDrawable gld ) { // TODO Auto-generated method stub GL2 gl = gld.getGL().getGL2(); gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_TEST ); gl.glMatrixMode( GL2.GL_MODELVIEW ); gl.glLoadIdentity(); gl.glTranslatef( 0.0f, 0.0f, -10.0f ); gl.glRotatef( 12, 1.0f, 0.0f, 0.0f ); gl.glRotatef( 40, 0.0f, 1.0f, 0.0f ); fBuffer = GLBuffers.newDirectFloatBuffer( fVertex.length ); fBuffer.put( fVertex ); fBuffer.rewind(); nBuffer = GLBuffers.newDirectFloatBuffer( nNormals.length ); nBuffer.put( nNormals ); nBuffer.rewind(); gl.glVertexPointer( 3, GL2.GL_FLOAT, 0, fBuffer ); gl.glNormalPointer( GL2.GL_FLOAT, 0, nBuffer ); gl.glEnableClientState( GL2.GL_VERTEX_ARRAY ); gl.glEnableClientState( GL2.GL_NORMAL_ARRAY ); gl.glDrawArrays( GL2.GL_POINTS, 0, fVertex.length / 3 ); gl.glDrawArrays( GL2.GL_QUADS, 0, nNormals.length / 3 ); gl.glDisableClientState( GL2.GL_NORMAL_ARRAY ); gl.glDisableClientState( GL2.GL_VERTEX_ARRAY ); } public void init(GLAutoDrawable gld ) { // TODO Auto-generated method stub GL2 gl = gld.getGL().getGL2(); glu = new GLU(); gl.glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); //gl.glEnable( GL2.GL_DEPTH_TEST ); gl.glMatrixMode( GL2.GL_PROJECTION ); gl.glLoadIdentity(); glu.gluPerspective( 45.0, 500.0 / 500.0, 1.0, 500.0 ); gl.glPointSize( 5.0f ); IterateArray(); } public void IterateArray() { loadModel(); for( int i = 0; i < vVerts.size(); i++ ) { fVertex[ i ] = Float.parseFloat( vVerts.get( i ) ); } for( int y = 0; y < nVerts.size(); y++ ) { nNormals[ y ] = Float.parseFloat( nVerts.get( y ) ); } } [/code] |
Administrator
|
I haven't really looked at ur code, but for a working example on how to load a Wavefront .obj (codepathes for vertices, polygons, textures and normals) with JOGL2 using VBO's take a look here: WavefrontObjectLoader_VertexBufferObject.java
|
Free forum by Nabble | Edit this page |