unlekker.data
Class STL

java.lang.Object
  extended by processing.core.PImage
      extended by processing.core.PGraphics
          extended by processing.core.PGraphics3D
              extended by unlekker.data.STL
All Implemented Interfaces:
java.lang.Cloneable, processing.core.PConstants

public class STL
extends processing.core.PGraphics3D

Class to export and import binary STL (Stereolithography) files from Processing. STL files are typically used for rapid prototyping, and consist of simple triangle data.

Using Processing's beginRaw() mechanism geometry can be output through this class. STL files can also be loaded into memory.

I recommend the excellent Open Source object viewer MeshLab for checking STL models. It will show inverted normals, invalid polygons and so on. It will even attempt some limited repairs of damaged files.


Field Summary
 STLFace[] f
          Array of STLFace objects comprising the current geometry.
 int num
          Current number of polygons
 
Fields inherited from class processing.core.PGraphics3D
lightingDependsOnVertexPosition, line, shape_index, triangle
 
Fields inherited from class processing.core.PGraphics
A, AB, AG, ambientB, ambientG, ambientR, AR, AUTO_NORMAL, B, backgroundColor, BEEN_LIT, bezierDetail, camera, cameraFar, cameraFOV, cameraInv, cameraNear, cameraX, cameraY, cameraZ, cameraAspect, colorMode, colorModeA, colorModeX, colorModeY, colorModeZ, currentLightFalloffConstant, currentLightFalloffLinear, currentLightFalloffQuadratic, currentLightSpecular, curveTightness, DA, DB, DG, DR, EB, EG, ellipseMode, emissiveB, emissiveG, emissiveR, ER, fill, fillColor, G, height1, image, INDEX, lightCount, lightDiffuse, lightFalloffConstant, lightFalloffLinear, lightFalloffQuadratic, lightNormal, lightPosition, lightSpecular, lightSpotAngle, lightSpotAngleCos, lightSpotConcentration, lightType, LINE_FIELD_COUNT, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33, MANUAL_SHAPE_NORMAL, MANUAL_VERTEX_NORMAL, MAX_LIGHTS, modelview, modelviewInv, MX, MY, MZ, normalCount, normalMode, normalX, normalY, normalZ, NX, NY, NZ, pixelCount, projection, R, raw, rectMode, SA, SB, SG, SHINE, shininess, SPA, SPB, specularA, specularB, specularG, specularR, SPG, sphereDetail, SPR, SR, stencil, stroke, STROKE_MODE, STROKE_WEIGHT, strokeCap, strokeColor, strokeJoin, strokeWeight, SW, textAlign, textAlignY, textFont, textFontNative, textFontNativeMetrics, textLeading, textMode, textSize, TEXTURE_INDEX, textureImage, textureMode, textureU, textureV, textX, textY, textZ, tint, tintColor, TRI_DIFFUSE_A, TRI_DIFFUSE_B, TRI_DIFFUSE_G, TRI_DIFFUSE_R, TRI_SPECULAR_A, TRI_SPECULAR_B, TRI_SPECULAR_G, TRI_SPECULAR_R, TRIANGLE_COLOR_COUNT, TRIANGLE_FIELD_COUNT, U, V, VERTEX_FIELD_COUNT, VERTEX1, VERTEX2, VERTEX3, VW, VX, VY, VZ, width1, X, Y, Z, zbuffer
 
Fields inherited from class processing.core.PImage
cache, format, height, imageMode, modified, mx1, mx2, my1, my2, parent, pixels, smooth, width
 
Fields inherited from interface processing.core.PConstants
ADD, ALPHA, ALPHA_MASK, ALT, AMBIENT, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BURN, CENTER, CENTER_RADIUS, CHATTER, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_DEPTH_TEST, DISABLE_ERROR_REPORT, DISABLE_TEXT_SMOOTH, DODGE, DOWN, DXF, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_NATIVE_FONTS, ENTER, EPSILON, ERODE, ESC, EXCLUSION, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINES, LINUX, MACOS9, MACOSX, MITER, MODEL, MOVE, MULTIPLY, NO_FLYING_POO, NORMALIZED, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PDF, PERSPECTIVE, PI, PIXEL_CENTER, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD_STRIP, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPOT, SQUARE, SUBTRACT, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, WAIT, WHITESPACE, WINDOWS
 
Constructor Summary
STL(int width, int height, processing.core.PApplet applet, java.lang.String filename)
          Constructor for use with beginRaw().
STL(processing.core.PApplet applet, java.lang.String path)
          Constructor for loading STL files.
 
Method Summary
 void beginShape(int kind)
          Start a new shape.
 void calcBounds()
          Calculates the bounding box of the object.
 void center()
          Centers the object around the world origin.
 void dispose()
          Handle any takedown for this graphics context.
 void draw()
          Draws the object.
 void endShape(int mode)
           
 void normalize(float m)
          Normalizes the object to a absolute scale
 void vertex(float x, float y)
           
 void vertex(float x, float y, float z)
           
 
Methods inherited from class processing.core.PGraphics3D
ambient, ambient, ambient, ambientLight, ambientLight, applyMatrix, applyMatrix, background, beginCamera, beginDraw, bezierVertex, bezierVertex, box, box, camera, camera, defaults, directionalLight, emissive, emissive, emissive, endCamera, endDraw, frustum, lightFalloff, lights, lightSpecular, loadMatrix, modelX, modelY, modelZ, normal, noSmooth, ortho, ortho, perspective, perspective, point, point, pointLight, popMatrix, printCamera, printMatrix, printProjection, pushMatrix, quad, resetMatrix, resize, rotate, rotate, rotateX, rotateY, rotateZ, scale, scale, scale, screenX, screenX, screenY, screenY, screenZ, shininess, smooth, specular, specular, specular, specular, specular, sphere, sphereDetail, spotLight, strokeCap, strokeJoin, texture, translate, translate, triangle, triangulate_polygon, vertex, vertex
 
Methods inherited from class processing.core.PGraphics
alpha, arc, background, background, background, background, background, background, beginRaw, beginShape, bezier, bezier, bezierDetail, bezierPoint, bezierTangent, blue, breakShape, brightness, color, color, color, color, color, color, color, color, color, colorMode, colorMode, colorMode, colorMode, curve, curve, curveDetail, curvePoint, curveTangent, curveTightness, curveVertex, curveVertex, displayable, ellipse, ellipseMode, endRaw, endShape, fill, fill, fill, fill, fill, fill, green, hint, hue, image, image, image, lerpColor, lerpColor, line, line, mask, mask, noFill, noHint, noStroke, noTint, rect, rectMode, red, requestDisplay, saturation, setMainDrawingSurface, stroke, stroke, stroke, stroke, stroke, stroke, strokeWeight, text, text, text, text, text, text, text, text, text, text, text, text, textAlign, textAlign, textAscent, textDescent, textFont, textFont, textLeading, textMode, textSize, textureMode, textWidth, textWidth, tint, tint, tint, tint, tint, tint
 
Methods inherited from class processing.core.PImage
blend, blend, blendColor, clone, copy, copy, filter, filter, get, get, get, imageMode, init, loadPixels, save, set, set, updatePixels, updatePixels
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

num

public int num
Current number of polygons


f

public STLFace[] f
Array of STLFace objects comprising the current geometry.

Constructor Detail

STL

public STL(int width,
           int height,
           processing.core.PApplet applet,
           java.lang.String filename)
Constructor for use with beginRaw().

Parameters:
filename - Name of file to output.

STL

public STL(processing.core.PApplet applet,
           java.lang.String path)
Constructor for loading STL files. Once loaded, draw() can be used to draw the geometry on the canvas.

Parameters:
filename - Name of file to open.
See Also:
draw()
Method Detail

draw

public void draw()
Draws the object.


calcBounds

public void calcBounds()
Calculates the bounding box of the object.


center

public void center()
Centers the object around the world origin.


normalize

public void normalize(float m)
Normalizes the object to a absolute scale


dispose

public void dispose()
Description copied from class: processing.core.PGraphics
Handle any takedown for this graphics context.

This is called when a sketch is shut down and this renderer was specified using the size() command, or inside endRecord() and endRaw(), in order to shut things off.

Overrides:
dispose in class processing.core.PGraphics

beginShape

public void beginShape(int kind)
Description copied from class: processing.core.PGraphics
Start a new shape.

Differences between beginShape() and line() and point() methods.

beginShape() is intended to be more flexible at the expense of being a little more complicated to use. it handles more complicated shapes that can consist of many connected lines (so you get joins) or lines mixed with curves.

The line() and point() command are for the far more common cases (particularly for our audience) that simply need to draw a line or a point on the screen.

From the code side of things, line() may or may not call beginShape() to do the drawing. In the beta code, they do, but in the alpha code, they did not. they might be implemented one way or the other depending on tradeoffs of runtime efficiency vs. implementation efficiency &mdash meaning the speed that things run at vs. the speed it takes me to write the code and maintain it. for beta, the latter is most important so that's how things are implemented.

Overrides:
beginShape in class processing.core.PGraphics3D

endShape

public void endShape(int mode)
Overrides:
endShape in class processing.core.PGraphics3D

vertex

public void vertex(float x,
                   float y)
Overrides:
vertex in class processing.core.PGraphics3D

vertex

public void vertex(float x,
                   float y,
                   float z)
Overrides:
vertex in class processing.core.PGraphics3D