/** * @param first * @param coordinate2 * @return */ private RenderableGeometry createVerticalGeometry( Coordinate first, Coordinate second, float minz, float maxz ) { float[] geom = new float[] { (float) first.x, (float) first.y, minz, (float) first.x, (float) first.y, maxz, (float) second.x, (float) second.y, maxz, (float) second.x, (float) second.y, minz }; float[] normal = new float[3]; float[] normals = new float[geom.length]; Vectors3f.normalizedNormal( geom, 0, normal ); normals[0] = normals[3] = normals[6] = normals[9] = normal[0]; normals[1] = normals[4] = normals[7] = normals[10] = normal[1]; normals[2] = normals[5] = normals[8] = normals[11] = normal[2]; return new RenderableGeometry( geom, GL.GL_QUADS, normals, false ); }
/** * @param renderableGeometry * @param out * @throws IOException */ private void writePlainGeometry( RenderableGeometry renderableGeometry, DataOutputStream out ) throws IOException { writeStyle( renderableGeometry.getStyle(), out ); out.writeInt( renderableGeometry.getOpenGLType() ); // coords FloatBuffer fb = getBuffer( renderableGeometry.getCoordBuffer(), renderableGeometry.getCoordPosition(), renderableGeometry.getOrdinateCount(), VertexType.VertexCoordinates ); writeFloatBuffer( fb, out, VertexType.VertexCoordinates ); // normals fb = getBuffer( renderableGeometry.getNormalBuffer(), renderableGeometry.getNormalPosition(), renderableGeometry.getOrdinateCount(), VertexType.Normals ); writeFloatBuffer( fb, out, VertexType.Normals ); }
/** * * @param rqm * @return List of points of a 3D object projected onto x/y-plane */ private Coordinate[] projectToPlane( RenderableQualityModel rqm ) { int length = 0; for ( RenderableQualityModelPart qmp : rqm.getQualityModelParts() ) { length += ( (RenderableGeometry) qmp ).getVertexCount(); } Coordinate[] coords = new Coordinate[length]; int i = 0; for ( RenderableQualityModelPart qmp : rqm.getQualityModelParts() ) { RenderableGeometry rg = (RenderableGeometry) qmp; FloatBuffer coordBuffer = rg.getReadOnlyCoordBuffer(); coordBuffer.rewind(); int cap = coordBuffer.capacity(); while ( coordBuffer.position() < cap ) { coords[i++] = new Coordinate( coordBuffer.get(), coordBuffer.get() ); // ignore z. coordBuffer.get(); } } return coords; }
/** * Create a renderable geometry from the given {@link SimpleAccessGeometry} by tesselating it. * * @param originalGeometry * may not be null. * @return the {@link RenderableGeometry} or <code>null</code> if the given geometry could not be triangulated. */ public final RenderableGeometry tesselateGeometry( SimpleAccessGeometry originalGeometry ) { GLUtessellator tess = glu.gluNewTess(); if ( originalGeometry == null ) { throw new NullPointerException( "The original geometry may not be null" ); } GeometryCallBack callBack = createAndRegisterCallBack( tess, originalGeometry ); RenderableGeometry result = tesselatePolygon( tess, callBack ); if ( result != null && LOG.isTraceEnabled() ) { LOG.trace( "Resulting renderable has " + result.getVertexCount() + " number of vertices." ); } glu.gluDeleteTess( tess ); return result; }
if ( rqmp != null ) { RenderableGeometry geom = (RenderableGeometry) rqmp; FloatBuffer fb = geom.getCoordBuffer(); fb.rewind(); int position = fb.position(); if ( rqmp != null ) { RenderableGeometry geom = (RenderableGeometry) rqmp; FloatBuffer fb = geom.getCoordBuffer(); fb.rewind(); int i = 0;
public void renderPrepared( RenderContext glRenderContext, DirectGeometryBuffer geomBuffer ) { enableArrays( glRenderContext, geomBuffer ); GL context = glRenderContext.getContext(); normalBuffer.rewind(); context.glPushAttrib( GL.GL_CURRENT_BIT | GL.GL_LIGHTING_BIT ); // context.glMaterialfv( GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, ambientColor, 0 ); context.glMaterialfv( GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, diffuseColor, 0 ); context.glMaterialfv( GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, specularColor, 0 ); context.glMaterialfv( GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, emmisiveColor, 0 ); context.glMaterialf( GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, style.getShininess() ); context.glDrawArrays( openGLType, 0, vertexCount ); context.glPopAttrib(); disableArrays( glRenderContext ); }
@Override protected void enableArrays( RenderContext glRenderContext, DirectGeometryBuffer geomBuffer ) { super.disableArrays( glRenderContext ); }
@Override protected void enableArrays( RenderContext glRenderContext, DirectGeometryBuffer geomBuffer ) { super.enableArrays( glRenderContext, geomBuffer ); if ( texturePosition >= 0 && textureBuffer == null && geomBuffer != null ) { textureBuffer = geomBuffer.getTextureCoordinates( texturePosition, textureOrdinatesCount ); if ( textureBuffer == null ) { texturePosition = -1; } } if ( textureBuffer != null ) { glRenderContext.getContext().glEnable( GL.GL_TEXTURE_2D ); TexturePool.loadTexture( glRenderContext, texture ); glRenderContext.getContext().glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY ); glRenderContext.getContext().glTexCoordPointer( 2, GL.GL_FLOAT, 0, textureBuffer ); } }
RenderableGeometry result = tesselatePolygon( tess, callBack ); if ( result != null ) { LOG.trace( "Resulting renderable has " + result.getVertexCount() + " number of vertices." ); results.add( result );
@Override public void disableArrays( RenderContext glRenderContext ) { super.disableArrays( glRenderContext ); LOG.trace( "Disabling array state and texture 2d" ); glRenderContext.getContext().glDisableClientState( GL.GL_TEXTURE_COORD_ARRAY ); glRenderContext.getContext().glDisable( GL.GL_TEXTURE_2D ); }
/** * Calculate the normals for the tesselated geometry and return a renderable geometry created from the given * {@link SimpleAccessGeometry} * * @param useDirectBuffers * to use direct buffers instead of heap buffers. * * @return the tesselated {@link SimpleAccessGeometry} as a {@link RenderableGeometry} */ public RenderableGeometry createRenderableGeometry( boolean useDirectBuffers ) { return new RenderableGeometry( getTesselatedCoordinates(), getOpenGLType(), calculateNormals(), geom.getStyle(), useDirectBuffers ); }
/** * * @param rqm * @return List of points of a 3D object projected onto x/y-plane */ private float[] retrieveCoords( RenderableQualityModel rqm ) { int length = 0; for ( RenderableQualityModelPart qmp : rqm.getQualityModelParts() ) { length += ( (RenderableGeometry) qmp ).getVertexCount(); } float[] coords = new float[length * 3]; int i = 0; for ( RenderableQualityModelPart qmp : rqm.getQualityModelParts() ) { RenderableGeometry rg = (RenderableGeometry) qmp; FloatBuffer coordBuffer = rg.getReadOnlyCoordBuffer(); coordBuffer.rewind(); int cap = coordBuffer.capacity(); while ( coordBuffer.position() < cap ) { coords[i++] = coordBuffer.get(); coords[i++] = coordBuffer.get(); coords[i++] = coordBuffer.get(); } } return coords; }
result = new RenderableGeometry( coordPositions[0], ( coordPositions[1] / 3 ), glType, normalPositions[0], style ); } else { result = new RenderableGeometry( coordBuffer, glType, normalBuffer, style );
if ( bb == null ) { if ( texCoordID == null ) { geometries.add( new RenderableGeometry( coords, glType, normals, style, false ) ); } else { geometries.add( new RenderableTexturedGeometry( coords, glType, normals, style,