unlekker.modelbuilder
Class UGeometry

java.lang.Object
  extended by unlekker.modelbuilder.UGeometry
All Implemented Interfaces:
processing.core.PConstants

public class UGeometry
extends java.lang.Object
implements processing.core.PConstants


Field Summary
 BBox bb
          Boundng box.
 float d
           
 UFace[] face
          List of faces.
 int faceNum
          Current number of faces.
 float h
           
 java.lang.String name
           
static java.lang.String NONAME
           
 UVertexList[] vl
          Array of vertex lists stored in this object.
 int vln
          Number of vertex lists stored in this object.
 float w
           
 
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, PATH, 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
UGeometry()
          Create unnamed instance.
UGeometry(java.lang.String _name)
          Create named instance.
UGeometry(UGeometry _g)
          Create copy of existing UGeometry object.
 
Method Summary
 UGeometry add(UGeometry g)
          Adds all the faces of a UGeometry instance.
 UGeometry add(UVertexList vv)
          Adds a UVertexList object to the vl array.
 void addFace(UFace f)
          Add single face
 void addFace(UVec3 v1, UVec3 v2, UVec3 v3)
          Adds single face from three UVec3 objects.
 void beginShape(int _type)
          Starts building a new series of faces, using the same logic as PApplet.beginShape().
 void calcBounds()
           
 void calcFaceNormals()
           
 void center()
          Calculates bounding box and centers all faces by calling translate(-bb.c.x,-bb.c.y,-bb.c.z)
 void draw(processing.core.PApplet p)
          Draws all faces contained in this UGeometry object.
 void drawVertexLists(processing.core.PApplet p)
          Convenience method to call UVertexList.drawVertices() on all vertex lists.
 void endShape()
           
static UGeometry extrude(UVertexList vl, float z, boolean reverse)
          Produces a UGeometry mesh by extruding a QUAD_STRIP along its face normal.
 UGeometry getCopy()
          Convenience method to produce a copy of this UGeometry instance.
 void quadStrip(UVertexList[] vl, int vln)
          Adds a mesh of QUAD_STRIPs built from an array of vertex lists.
 void quadStrip(UVertexList vl, boolean reverseOrder)
          Adds QUAD_STRIP of faces from a list of vertex pairs.
 void quadStrip(UVertexList v1, UVertexList v2)
          Adds QUAD_STRIP of faces built from two vertex lists.
 void quadStrip(UVertexList v1, UVertexList v2, boolean reverse)
          Adds QUAD_STRIP of faces built from two vertex lists.
 void reset()
          Resets geometry to empty.
 UGeometry rotateX(float a)
           
 UGeometry rotateY(float a)
           
 UGeometry rotateZ(float a)
           
 UGeometry scale(float m)
           
 UGeometry scale(float mx, float my, float mz)
           
 UGeometry setDimensions(float m)
           
 UGeometry setDimensionsXY(float m)
           
 UGeometry setDimensionsXZ(float m)
           
 UGeometry setDimensionsYZ(float m)
           
 float surfaceArea()
           
 UGeometry toOrigin()
          Calculates bounding box and translates the mesh to origin by calling translate(-bb.min.x,-bb.min.y,-bb.min.z);
 UGeometry translate(float x, float y, float z)
           
 UGeometry translate(UVec3 vv)
           
static float triangleArea(UVec3 v1, UVec3 v2, UVec3 v3)
           
 void triangleFan(UVertexList vl, boolean reverseOrder)
          Adds a TRIANGLE_FAN constructed from input vertex list.
 void vertex(float x, float y, float z)
          Add vertex to shape being built by beginShape() / endShape()
 void vertex(UVec3 v)
          Add UVec3 vertex to shape being built by beginShape() / endShape() The vertex information is copied, leaving the original UVec3 instance unchanged.
 void vertex(UVec3[] _v, int nv)
          Adds array of UVec3 vertices to shape being built by beginShape() / endShape().
 void vertex(UVec3[] _v, int nv, boolean reverseOrder)
          Adds array of UVec3 vertices to shape being built by beginShape() / endShape().
 void vertex(UVertexList vl)
          Adds vertex list to shape being built by beginShape() / endShape().
 void vertex(UVertexList vl, boolean reverseOrder)
          Add vertex list to shape being built by beginShape() / endShape().
 void writeSTL(processing.core.PApplet p, java.lang.String filename)
          Output binary STL file of mesh geometry.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONAME

public static java.lang.String NONAME

name

public java.lang.String name

face

public UFace[] face
List of faces.


faceNum

public int faceNum
Current number of faces.


vl

public UVertexList[] vl
Array of vertex lists stored in this object.


vln

public int vln
Number of vertex lists stored in this object.


bb

public BBox bb
Boundng box.


w

public float w

d

public float d

h

public float h
Constructor Detail

UGeometry

public UGeometry()
Create unnamed instance.


UGeometry

public UGeometry(java.lang.String _name)
Create named instance.


UGeometry

public UGeometry(UGeometry _g)
Create copy of existing UGeometry object.

Method Detail

reset

public void reset()
Resets geometry to empty.


quadStrip

public void quadStrip(UVertexList vl,
                      boolean reverseOrder)
Adds QUAD_STRIP of faces from a list of vertex pairs.

Parameters:
vl - Array of vertex pairs
reverseOrder - Build in reverse order?

quadStrip

public void quadStrip(UVertexList v1,
                      UVertexList v2)
Adds QUAD_STRIP of faces built from two vertex lists.

Parameters:
v1 - First edge of QUAD_STRIP
v2 - Second edge of QUAD_STRIP

quadStrip

public void quadStrip(UVertexList v1,
                      UVertexList v2,
                      boolean reverse)
Adds QUAD_STRIP of faces built from two vertex lists.

Parameters:
v1 - First edge of QUAD_STRIP
v2 - Second edge of QUAD_STRIP
reverse - Build in reverse order?

quadStrip

public void quadStrip(UVertexList[] vl,
                      int vln)
Adds a mesh of QUAD_STRIPs built from an array of vertex lists. Each vertex list is treated as a single edge and will be connected to the next edge in the array. All vertex lists must have the same number of vertices.

Parameters:
vl - Array of vertex lists to be used as edges.
vln - Number of lists to use from array

triangleFan

public void triangleFan(UVertexList vl,
                        boolean reverseOrder)
Adds a TRIANGLE_FAN constructed from input vertex list.

Parameters:
vl - Array of vertex pairs
reverseOrder - Build in reverse order?

beginShape

public void beginShape(int _type)
Starts building a new series of faces, using the same logic as PApplet.beginShape(). Currently the following shape types are supported: TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, QUADS, QUAD_STRIP

Parameters:
_type - Shape type (TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, QUADS, QUAD_STRIP)

endShape

public void endShape()

vertex

public void vertex(float x,
                   float y,
                   float z)
Add vertex to shape being built by beginShape() / endShape()

Parameters:
x -
y -
z -

vertex

public void vertex(UVec3 v)
Add UVec3 vertex to shape being built by beginShape() / endShape() The vertex information is copied, leaving the original UVec3 instance unchanged.

Parameters:
v -

vertex

public void vertex(UVertexList vl,
                   boolean reverseOrder)
Add vertex list to shape being built by beginShape() / endShape(). All vertices are copied, leaving the original instances unchanged.

Parameters:
vl -
reverseOrder - Add in reverse order?

vertex

public void vertex(UVertexList vl)
Adds vertex list to shape being built by beginShape() / endShape(). All vertices are copied, leaving the original instances unchanged.


vertex

public void vertex(UVec3[] _v,
                   int nv)
Adds array of UVec3 vertices to shape being built by beginShape() / endShape(). All objects are copied, leaving the original instances unchanged.

Parameters:
_v - Array of vertices
nv - Number of vertices to add

vertex

public void vertex(UVec3[] _v,
                   int nv,
                   boolean reverseOrder)
Adds array of UVec3 vertices to shape being built by beginShape() / endShape(). All objects are copied, leaving the original instances unchanged.

Parameters:
_v - Array of vertices
nv - Number of vertices to add
reverseOrder - Add in reverse order?

addFace

public void addFace(UVec3 v1,
                    UVec3 v2,
                    UVec3 v3)
Adds single face from three UVec3 objects.

Parameters:
v1 -
v2 -
v3 -

add

public UGeometry add(UVertexList vv)
Adds a UVertexList object to the vl array. The object is stored by reference, so any changes made to it through this class will also affect the original instance. Not to be confused with vertex(UVertexList vl)

Parameters:
vv -
Returns:

add

public UGeometry add(UGeometry g)
Adds all the faces of a UGeometry instance. The faces is copied and the original instance is left unchanged.

Parameters:
g - UGeometry to add
Returns:

addFace

public void addFace(UFace f)
Add single face

Parameters:
f -

draw

public void draw(processing.core.PApplet p)
Draws all faces contained in this UGeometry object.

Parameters:
p - Reference to PApplet instance to draw into

rotateX

public UGeometry rotateX(float a)

rotateY

public UGeometry rotateY(float a)

rotateZ

public UGeometry rotateZ(float a)

translate

public UGeometry translate(float x,
                           float y,
                           float z)

translate

public UGeometry translate(UVec3 vv)

toOrigin

public UGeometry toOrigin()
Calculates bounding box and translates the mesh to origin by calling translate(-bb.min.x,-bb.min.y,-bb.min.z);


scale

public UGeometry scale(float m)

scale

public UGeometry scale(float mx,
                       float my,
                       float mz)

getCopy

public UGeometry getCopy()
Convenience method to produce a copy of this UGeometry instance.

Returns:
Copy of UGeometry

extrude

public static UGeometry extrude(UVertexList vl,
                                float z,
                                boolean reverse)
Produces a UGeometry mesh by extruding a QUAD_STRIP along its face normal. The input is a list of vertices making up the QUAD_STRIP. The face normal of the first quad is used to calculate the extrusion, multiplied by the parameter z.

Parameters:
vl - Vertex list defining a QUAD_STRIP mesh
z - Offset to extrude by along the face normal, can be positive or negative
reverse - Construct in reverse order? Useful in case face normals of resulting mesh is incorrect.
Returns:

calcBounds

public void calcBounds()

calcFaceNormals

public void calcFaceNormals()

center

public void center()
Calculates bounding box and centers all faces by calling translate(-bb.c.x,-bb.c.y,-bb.c.z)


setDimensions

public UGeometry setDimensions(float m)

setDimensionsXZ

public UGeometry setDimensionsXZ(float m)

setDimensionsXY

public UGeometry setDimensionsXY(float m)

setDimensionsYZ

public UGeometry setDimensionsYZ(float m)

writeSTL

public void writeSTL(processing.core.PApplet p,
                     java.lang.String filename)
Output binary STL file of mesh geometry.

Parameters:
p - Reference to PApplet instance
filename - Name of file to save to

triangleArea

public static float triangleArea(UVec3 v1,
                                 UVec3 v2,
                                 UVec3 v3)

surfaceArea

public float surfaceArea()

drawVertexLists

public void drawVertexLists(processing.core.PApplet p)
Convenience method to call UVertexList.drawVertices() on all vertex lists. NOTE: begin/endShape() are not called.

Parameters:
p - Reference to PApplet instance