org.mt4j.components.visibleComponents
Class GeometryInfo

java.lang.Object
  extended by org.mt4j.components.visibleComponents.GeometryInfo

public class GeometryInfo
extends java.lang.Object

    

A class which holds the vertices and eventually also the normals, colors, indices, displaylist ids,and vbo ids of the geometry.

Author:
C.Ruff

Constructor Summary
GeometryInfo(processing.core.PApplet pApplet, Vertex[] vertices)
          Creates a new GeometryInfo.
GeometryInfo(processing.core.PApplet pApplet, Vertex[] vertices, int[] indices)
          Instantiates a new geometry info.
GeometryInfo(processing.core.PApplet pApplet, Vertex[] vertices, Vector3D[] normals)
          Instantiates a new geometry info.
GeometryInfo(processing.core.PApplet pApplet, Vertex[] vertices, Vector3D[] normals, int[] indices)
          Creates a new GeometryInfo with vertices, normals and indices.
 
Method Summary
 void deleteAllVBOs()
          Deletes all VBOs of the geometry.
 void deleteDisplayLists()
          Delete the the displaylists of that geometry.
 void generateDisplayLists(boolean useTexture, processing.core.PImage texture, int fillDrawMode, boolean drawSmooth, float strokeWeight)
          Generates 2 openGL display lists for drawing this shape.
 void generateOrUpdateAllVBOs()
          Generates Vertex Buffer Objects (VBO) from the local buffers for Vertex, Texture, Color, StrokeColor and Normals.
 void generateOrUpdateBuffersLocal(StyleInfo styleInfo)
          Updates all draw buffers with the current settings
 java.nio.FloatBuffer getColorBuff()
          Gets the color buff.
 int[] getDisplayListIDs()
          Returns the IDs (names) of the display lists if they have been generated!
 java.nio.IntBuffer getIndexBuff()
          Gets the index buff.
 int[] getIndices()
          Gets the indices.
 Vector3D[] getNormals()
          Gets the normals.
 java.nio.FloatBuffer getNormalsBuff()
          Gets the normals buff.
 processing.core.PApplet getRenderer()
          Gets the renderer.
 java.nio.FloatBuffer getStrokeColBuff()
          Gets the stroke col buff.
 java.nio.FloatBuffer getTexBuff()
          Gets the tex buff.
 int getVBOColorName()
          Gets the vBO color name.
 int getVBONormalsName()
          Gets the vBO normals name.
 int getVBOStrokeColorName()
          Gets the vBO stroke color name.
 int getVBOTextureName()
          Gets the vBO texture name.
 int getVBOVerticesName()
          Gets the vBO vertices name.
 java.nio.FloatBuffer getVertBuff()
          Gets the vert buff.
 int getVertexCount()
          Gets the vertex count.
 Vertex[] getVertices()
          Returns the vertices of this shape without any transformations applied
Caution: If you alter them in anyway, changes will only be consistent by calling the setNewVertices() method!.
 boolean isContainsNormals()
          Returns true, if a normals array for the geometry has been set.
 boolean isIndexed()
          Returns true, if an indices array for the geometry has been set.
 void reconstruct(Vertex[] vertices, Vector3D[] normals, int[] indices, boolean createOrUpdateOGLBuffers, boolean createOrUpdateVBO, StyleInfo styleInfo)
          Reconstructs the geometry with the given parameters.
 void setDisplayListIDs(int[] ids)
          Sets the display lists for this shape.
 void setIndices(int[] indices, boolean createOrUpdateOGLBuffers)
          Adds indices to the geometry.
 void setNormals(Vector3D[] normals, boolean createOrUpdateOGLBuffers, boolean createOrUpdateVBO)
          Adds normals to the geometry info.
 void setStrokeColorAll(float r, float g, float b, float a)
          Sets the stroke color all.
 void setVerticesColorAll(float r, float g, float b, float a)
          Sets the vertices color all.
 void updateColorVBO(java.nio.FloatBuffer colorBuffer)
          Update color vbo.
 void updateNormalsVBO(java.nio.FloatBuffer normalsBuffer, boolean setAsNewNormalBuffer, boolean setAsNewNormalArray)
          Update normals vbo.
 void updateStrokeColorVBO(java.nio.FloatBuffer strokeColorBuffer)
          Update stroke color vbo.
 void updateTextureBuffer(boolean updateVBO)
          Generates new texture buffer for openGL use.
 void updateTextureVBO(java.nio.FloatBuffer textureBuffer)
          Update texture vbo.
 void updateVertexVBO(java.nio.FloatBuffer vertexBuffer, boolean setAsNewVertexBuffer, boolean setAsNewVertexArray)
          Updates the vertex buffer objects and sets the specified vertexbuffer to the geometryinfo.
 void updateVerticesColorBuffer()
          Generates new color buffers for openGL use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeometryInfo

public GeometryInfo(processing.core.PApplet pApplet,
                    Vertex[] vertices)
Creates a new GeometryInfo.
As only vertices are supplied, the normals (+ normal buffers, normal vbos) will be null.
The indices array and indices buffer will also be null.

Parameters:
pApplet - the applet
vertices - the vertices

GeometryInfo

public GeometryInfo(processing.core.PApplet pApplet,
                    Vertex[] vertices,
                    Vector3D[] normals)
Instantiates a new geometry info.

Parameters:
pApplet - the applet
vertices - the vertices
normals - the normals

GeometryInfo

public GeometryInfo(processing.core.PApplet pApplet,
                    Vertex[] vertices,
                    int[] indices)
Instantiates a new geometry info.

Parameters:
pApplet - the applet
vertices - the vertices
indices - the indices

GeometryInfo

public GeometryInfo(processing.core.PApplet pApplet,
                    Vertex[] vertices,
                    Vector3D[] normals,
                    int[] indices)
Creates a new GeometryInfo with vertices, normals and indices.
The number of normals should match the number of indices or vertices.

Parameters:
pApplet - the applet
vertices - the vertices
normals - the normals
indices - the indices
Method Detail

reconstruct

public void reconstruct(Vertex[] vertices,
                        Vector3D[] normals,
                        int[] indices,
                        boolean createOrUpdateOGLBuffers,
                        boolean createOrUpdateVBO,
                        StyleInfo styleInfo)
Reconstructs the geometry with the given parameters. Normals, indices and styleinfo may be null.

Parameters:
vertices - the vertices
normals - the normals
indices - the indices
createOrUpdateOGLBuffers - the create or update ogl buffers
createOrUpdateVBO - the create or update vbo
styleInfo - the style info

setIndices

public void setIndices(int[] indices,
                       boolean createOrUpdateOGLBuffers)
Adds indices to the geometry. Marks the geometry to be indexed. (isIndexed() returns true)
If useopenGL is true, a IntBuffer is also created for use with OpenGl. If the indices array is != null, the geometry will return true at isIndexed() afterwards

Parameters:
indices - the indices
createOrUpdateOGLBuffers - the create or update ogl buffers

getIndices

public int[] getIndices()
Gets the indices.

Returns:
the indices the array if indices

isIndexed

public boolean isIndexed()
Returns true, if an indices array for the geometry has been set.

Returns:
true, if checks if is indexed true, if indexed

setNormals

public void setNormals(Vector3D[] normals,
                       boolean createOrUpdateOGLBuffers,
                       boolean createOrUpdateVBO)
Adds normals to the geometry info.
Also creates/updates the buffers and vbos of the normals if the booleans are set.
If the normal vector is != null, the geometry will return true at isContainsNormals() afterwards

Parameters:
normals - the normals
createOrUpdateOGLBuffers - the create or update ogl buffers
createOrUpdateVBO - the create or update vbo

getNormals

public Vector3D[] getNormals()
Gets the normals.

Returns:
the normals The array of normal vectors

isContainsNormals

public boolean isContainsNormals()
Returns true, if a normals array for the geometry has been set.

Returns:
true, if checks if is contains normals true, if the geometry contains normals

generateOrUpdateBuffersLocal

public void generateOrUpdateBuffersLocal(StyleInfo styleInfo)
Updates all draw buffers with the current settings

Parameters:
styleInfo - the style info

getColorBuff

public java.nio.FloatBuffer getColorBuff()
Gets the color buff.

Returns:
the color buff

getIndexBuff

public java.nio.IntBuffer getIndexBuff()
Gets the index buff.

Returns:
the index buff

getStrokeColBuff

public java.nio.FloatBuffer getStrokeColBuff()
Gets the stroke col buff.

Returns:
the stroke col buff

getTexBuff

public java.nio.FloatBuffer getTexBuff()
Gets the tex buff.

Returns:
the tex buff

getVertBuff

public java.nio.FloatBuffer getVertBuff()
Gets the vert buff.

Returns:
the vert buff

getNormalsBuff

public java.nio.FloatBuffer getNormalsBuff()
Gets the normals buff.

Returns:
the normals buff

generateOrUpdateAllVBOs

public void generateOrUpdateAllVBOs()
Generates Vertex Buffer Objects (VBO) from the local buffers for Vertex, Texture, Color, StrokeColor and Normals. CREATES THEM ONLY IF THEY DONT EXIST YET!

If the geometry had vbos already, we should delete them first usually.


updateVertexVBO


public void updateVertexVBO(java.nio.FloatBuffer vertexBuffer,
                            boolean setAsNewVertexBuffer,
                            boolean setAsNewVertexArray)
Updates the vertex buffer objects and sets the specified vertexbuffer to the geometryinfo. If setAsNewVertexBuffer is set to true, this also updates the vertex array. (not cheap but the geometry may act inconsistent if the arrays are not also updated - depends on usage).
If we only want the vbo to be updated we set both booleans to false

Parameters:
vertexBuffer - the vertex buffer
setAsNewVertexBuffer - the set as new vertex buffer
setAsNewVertexArray - the set as new vertex array

updateTextureVBO

public void updateTextureVBO(java.nio.FloatBuffer textureBuffer)
Update texture vbo.

Parameters:
textureBuffer - the texture buffer

updateColorVBO

public void updateColorVBO(java.nio.FloatBuffer colorBuffer)
Update color vbo.

Parameters:
colorBuffer - the color buffer

updateStrokeColorVBO

public void updateStrokeColorVBO(java.nio.FloatBuffer strokeColorBuffer)
Update stroke color vbo.

Parameters:
strokeColorBuffer - the stroke color buffer

updateNormalsVBO

public void updateNormalsVBO(java.nio.FloatBuffer normalsBuffer,
                             boolean setAsNewNormalBuffer,
                             boolean setAsNewNormalArray)
Update normals vbo.

Parameters:
normalsBuffer - the normals buffer
setAsNewNormalBuffer - the set as new normal buffer
setAsNewNormalArray - the set as new normal array

deleteAllVBOs

public void deleteAllVBOs()
Deletes all VBOs of the geometry.


getVBOVerticesName

public int getVBOVerticesName()
Gets the vBO vertices name.

Returns:
the vBO vertices name

getVBOColorName

public int getVBOColorName()
Gets the vBO color name.

Returns:
the vBO color name

getVBOTextureName

public int getVBOTextureName()
Gets the vBO texture name.

Returns:
the vBO texture name

getVBOStrokeColorName

public int getVBOStrokeColorName()
Gets the vBO stroke color name.

Returns:
the vBO stroke color name

getVBONormalsName

public int getVBONormalsName()
Gets the vBO normals name.

Returns:
the vBO normals name

generateDisplayLists

public void generateDisplayLists(boolean useTexture,
                                 processing.core.PImage texture,
                                 int fillDrawMode,
                                 boolean drawSmooth,
                                 float strokeWeight)
Generates 2 openGL display lists for drawing this shape.
One for the interior (with textures etc.) and one for drawing the outline.
setUseDirectGL has to be set to true first!
To use the display lists for drawing, call setUseDisplayList()
NOTE: if a display list already existed, we should delete that first!

Parameters:
useTexture - the use texture
texture - the texture
fillDrawMode - the fill draw mode
drawSmooth - the draw smooth
strokeWeight - the stroke weight

deleteDisplayLists

public void deleteDisplayLists()
Delete the the displaylists of that geometry.


getDisplayListIDs

public int[] getDisplayListIDs()
Returns the IDs (names) of the display lists if they have been generated! setUseDisplayList has to be called first!.

Returns:
int[2] array where [0] is the list of the fill and [1] the list of the outline

setDisplayListIDs

public void setDisplayListIDs(int[] ids)
Sets the display lists for this shape.
The int array has to be of length=2 and contain 2 display list ids, generated with glGenlists

Parameters:
ids - the ids

getVertices

public Vertex[] getVertices()
Returns the vertices of this shape without any transformations applied
Caution: If you alter them in anyway, changes will only be consistent by calling the setNewVertices() method!.

Returns:
the untransformed vertices

setVerticesColorAll

public void setVerticesColorAll(float r,
                                float g,
                                float b,
                                float a)
Sets the vertices color all.

Parameters:
r - the r
g - the g
b - the b
a - the a

setStrokeColorAll

public void setStrokeColorAll(float r,
                              float g,
                              float b,
                              float a)
Sets the stroke color all.

Parameters:
r - the r
g - the g
b - the b
a - the a

updateVerticesColorBuffer

public void updateVerticesColorBuffer()
Generates new color buffers for openGL use.
This has to be called after manually changing a vertex color without using a method like setFillColor(..) to take effect.
Only makes sense when using OPENGL!
Doesent update strokecolors!


updateTextureBuffer

public void updateTextureBuffer(boolean updateVBO)
Generates new texture buffer for openGL use.
This has to be called after manually changing a vertex u,v texture coordinates in the vertex array.
Only makes sense when using OPENGL!

Parameters:
updateVBO - the update vbo

getVertexCount

public int getVertexCount()
Gets the vertex count.

Returns:
the vertex count

getRenderer

public processing.core.PApplet getRenderer()
Gets the renderer.

Returns:
the renderer