unlekker.modelbuilder
Class UVertexList

java.lang.Object
  extended by unlekker.modelbuilder.UVertexList
All Implemented Interfaces:
processing.core.PConstants, UConstants

public class UVertexList
extends java.lang.Object
implements UConstants

Utility class to deal with a list of vertices. Provides methods for building and transforming vertex lists. Most methods return a reference to self, allowing jQuery-style stringing of functions. Example:

UVertexList vl=new UVertexList();
vl.add(0,0,0).add(100,0,0);
vl.translate(0,100,0).scale(100).rotateX(PI);
 

Author:
Marius Watz

Field Summary
 BBox bb
          Boundng box.
 float d
           
 float h
           
 int n
          Number of vertices in list.
 UVec3[] v
          Array of vertices.
 float w
           
 
Fields inherited from interface unlekker.util.UConstants
A1H, A1W, classOBJ, classSTL, COMMACHAR, COMMASTR, DIRCHAR, DIRSTR, EOF, FADEIN, FADEINDONE, FADEOUT, FADEOUTDONE, GEOMETRY, GROUP, MODELRECORDER, PATH, POVRAY, PRIMITIVE, PShapeFamilyNames, PTTOCM, PTTOINCH, PTTOMM, saveDXF, saveJPG, saveMOV, saveOBJ, savePDF, savePNG, saveSTL, saveTGA, saveTILE, shapeTypes, TABCHAR, TABSTR, XYPLANE, XZPLANE, YZPLANE
 
Fields inherited from interface processing.core.PConstants
A, AB, ADD, AG, ALPHA, ALPHA_MASK, ALT, AMBIENT, AR, ARC, ARGB, ARROW, B, BACKSPACE, BASELINE, BEEN_LIT, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CENTER_DIAMETER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DA, DARKEST, DB, DEG_TO_RAD, DELETE, DG, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_OPENGL_2X_SMOOTH, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DR, DXF, EB, EDGE, EG, ELLIPSE, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ER, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, G, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMAL, NORMALIZED, NX, NY, NZ, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, R, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SA, SB, SCREEN, SG, SHAPE, SHIFT, SHINE, SOFT_LIGHT, SPB, SPG, SPHERE, SPOT, SPR, SQUARE, SR, SUBTRACT, SW, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, TX, TY, TZ, U, UP, V, VERTEX_FIELD_COUNT, VW, VX, VY, VZ, WAIT, WHITESPACE, WINDOWS, X, Y, Z
 
Constructor Summary
UVertexList()
          Creates empty vertex list.
UVertexList(java.lang.String in)
          Parses a VertexList from the string produced by VertexList.toDataString().
UVertexList(UVertexList _vl)
          Create new UVertexList by copying the UVertexList given as parameter, leaving the input unchanged.
 
Method Summary
 UVertexList add(float[] vv)
          Adds array of floats as vertices, treating values as XYZ triplets or XY duplets depending on whether vv.length%2==0 or vv.length%3==0.
 UVertexList add(float x, float y)
          Convenience method to add X,Y vertices
 UVertexList add(float x, float y, float z)
          Adds x,y,z vertex to list
 UVertexList add(UVec3 _v)
           
 UVertexList add(UVertexList _vl)
          Adds all vertices from another vertex list.
 UVertexList addQuad(float[] q)
          Adds quad of vertices (order: bottom left, bottom right, top right, top left). if q.length%2==0 the array data treated as 2D XY duplets.
static UVertexList calcBezier(UVertexList curvePts, int steps)
          Calculates points along a 3D bezier curve, using the Bezier3D class.
 UVertexList calcBounds()
          Calculates bounding box
 UVertexList center()
          Translates all vertices by subtracting the centroid to each vertex, i.e. translate(-bb.c.x,-bb.c.y,-bb.c.z).
 void draw(processing.core.PApplet p)
          Calls beginShape() without parameters, then vertex() with all vertices in the vertex list before finally calling endShape().
 void drawQuadStrip(processing.core.PApplet p)
          Calls begin/endShape(QUAD_STRIP) and draws all vertices in the vertex list.
 void drawVertices(processing.core.PApplet p)
          Calls vertex() with all vertices in the vertex list.
static UVertexList getCircle(float R, int res)
          Convenience method to calculate res vertices along a circle of R radius
 UVertexList QStoOutline()
           
 UVertexList reset()
          Clears vertex list by setting n=0 and bb=null.
 UVertexList reverseOrder()
          Reverse order of vertices, so that v[n-1] becomes v[0] etc.
 UVertexList rotateX(float a)
          Rotates vertices in list around X axis
 UVertexList rotateY(float a)
          Rotates vertices in list around Y axis
 UVertexList rotateZ(float a)
          Rotates vertices in list around Z axis
 UVertexList scale(float m)
          Uniformly scales all vertices by multiplying with the value m.
 UVertexList scale(float mx, float my, float mz)
          Scales XYZ dimensions of all vertices by multiplying them with individual factors.
 UVertexList setDimensions(float m)
           
 UVertexList setDimensionsXY(float m)
           
 UVertexList setDimensionsXZ(float m)
           
 UVertexList setDimensionsYZ(float m)
           
 java.lang.String toDataString()
           
 UVertexList toOrigin()
           
 java.lang.String toString()
           
 UVertexList translate(float x, float y)
          Translates all vertices by adding x,y to each vertex's XY coordinates.
 UVertexList translate(float x, float y, float z)
          Translates all vertices by adding x,y,z to each vertex.
 UVertexList translate(UVec3 _v)
          Translates all vertices by adding the values of _v to each vertex.
 UVertexList translateNeg(UVec3 _v)
          Translates all vertices by subtracting the values of _v from each vertex.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

v

public UVec3[] v
Array of vertices. Grows automatically in size as vertices are added. May contain null values, always use n to get the current vertex count.


n

public int n
Number of vertices in list.


bb

public BBox bb
Boundng box. Automatically calculated by the setDimensions methods if bb==null.


w

public float w

d

public float d

h

public float h
Constructor Detail

UVertexList

public UVertexList()
Creates empty vertex list.


UVertexList

public UVertexList(UVertexList _vl)
Create new UVertexList by copying the UVertexList given as parameter, leaving the input unchanged.

Parameters:
_vl - UVertexList to copy.

UVertexList

public UVertexList(java.lang.String in)
Parses a VertexList from the string produced by VertexList.toDataString().

Method Detail

getCircle

public static UVertexList getCircle(float R,
                                    int res)
Convenience method to calculate res vertices along a circle of R radius

Parameters:
R - Radius of circle
res - Number of points to calculate
Returns:

QStoOutline

public UVertexList QStoOutline()

drawQuadStrip

public void drawQuadStrip(processing.core.PApplet p)
Calls begin/endShape(QUAD_STRIP) and draws all vertices in the vertex list.

Parameters:
p -

drawVertices

public void drawVertices(processing.core.PApplet p)
Calls vertex() with all vertices in the vertex list. NOTE: begin/endShape() are not called.

Parameters:
p -

draw

public void draw(processing.core.PApplet p)
Calls beginShape() without parameters, then vertex() with all vertices in the vertex list before finally calling endShape().

Parameters:
p -

calcBounds

public UVertexList calcBounds()
Calculates bounding box

Returns:
Returns reference to self

center

public UVertexList center()
Translates all vertices by subtracting the centroid to each vertex, i.e. translate(-bb.c.x,-bb.c.y,-bb.c.z). Calculates bounding box only if not already calculated (bb==null).

Returns:
Returns reference to self

toOrigin

public UVertexList toOrigin()

setDimensions

public UVertexList setDimensions(float m)

setDimensionsXZ

public UVertexList setDimensionsXZ(float m)

setDimensionsXY

public UVertexList setDimensionsXY(float m)

setDimensionsYZ

public UVertexList setDimensionsYZ(float m)

add

public UVertexList add(UVec3 _v)

add

public UVertexList add(float x,
                       float y)
Convenience method to add X,Y vertices

Parameters:
x -
y -
Returns:
Returns reference to self

add

public UVertexList add(float x,
                       float y,
                       float z)
Adds x,y,z vertex to list

Parameters:
x -
y -
z -
Returns:
Returns reference to self

add

public UVertexList add(float[] vv)
Adds array of floats as vertices, treating values as XYZ triplets or XY duplets depending on whether vv.length%2==0 or vv.length%3==0.

Parameters:
vv - Array of XY duplets or XYZ triplets.
Returns:
Returns reference to self

addQuad

public UVertexList addQuad(float[] q)
Adds quad of vertices (order: bottom left, bottom right, top right, top left). if q.length%2==0 the array data treated as 2D XY duplets.

Parameters:
vv - Array of XY duplets or XYZ triplets.
Returns:
Returns reference to self

rotateX

public UVertexList rotateX(float a)
Rotates vertices in list around X axis

Parameters:
a - Angle to rotate by.
Returns:
Returns reference to self

rotateY

public UVertexList rotateY(float a)
Rotates vertices in list around Y axis

Parameters:
a - Angle to rotate by.
Returns:
Returns reference to self

rotateZ

public UVertexList rotateZ(float a)
Rotates vertices in list around Z axis

Parameters:
a - Angle to rotate by.
Returns:
Returns reference to self

translateNeg

public UVertexList translateNeg(UVec3 _v)
Translates all vertices by subtracting the values of _v from each vertex.

Parameters:
_v - Vector to subtract
Returns:

translate

public UVertexList translate(UVec3 _v)
Translates all vertices by adding the values of _v to each vertex.

Parameters:
_v - Vector to add.
Returns:

translate

public UVertexList translate(float x,
                             float y,
                             float z)
Translates all vertices by adding x,y,z to each vertex.

Returns:

translate

public UVertexList translate(float x,
                             float y)
Translates all vertices by adding x,y to each vertex's XY coordinates.

Parameters:
_v - Vector to subtract
Returns:
Returns reference to self

scale

public UVertexList scale(float m)
Uniformly scales all vertices by multiplying with the value m.

Parameters:
m - Factor to scale by.
Returns:
Returns reference to self

scale

public UVertexList scale(float mx,
                         float my,
                         float mz)
Scales XYZ dimensions of all vertices by multiplying them with individual factors.

Parameters:
mx - Factor to scale X values.
my - Factor to scale Y values.
mz - Factor to scale Z values.
Returns:
Returns reference to self

calcBezier

public static UVertexList calcBezier(UVertexList curvePts,
                                     int steps)
Calculates points along a 3D bezier curve, using the Bezier3D class.

Parameters:
curvePts - Array of 4 vertices to be treated as control points.
steps - Number of vertices along the curve to calculate.
Returns:
New UVertexList with the calculated vertices

add

public UVertexList add(UVertexList _vl)
Adds all vertices from another vertex list. All vertices are copied as new UVec3 instances, so changes in either vertex list will not affect the other

Parameters:
_vl - Input vertex list
Returns:
Returns reference to self

reset

public UVertexList reset()
Clears vertex list by setting n=0 and bb=null.

Returns:
Returns reference to self

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toDataString

public java.lang.String toDataString()

reverseOrder

public UVertexList reverseOrder()
Reverse order of vertices, so that v[n-1] becomes v[0] etc.

Returns:
Returns reference to self