Shapes 3D  3.0
 All Classes Functions Variables Pages
shapes3d.Shape3D Class Referenceabstract
Inheritance diagram for shapes3d.Shape3D:

Public Member Functions

 Shape3D ()
 
abstract Shape3D getThis ()
 
void addPickHandler (Object obj, String methodName)
 
Shape3D pickable (boolean pickable)
 
boolean pickable ()
 
int nbrParts ()
 
Shape3D use (int parts_to_use)
 
Shape3D tag (String tag)
 
Shape3D tag (String tag, int parts)
 
String[] tags ()
 
Shape3D drawMode (int mode)
 
Shape3D drawMode (int mode, int parts)
 
int[] drawModes ()
 
Shape3D fill (int col)
 
Shape3D fill (int col, int parts)
 
int[] fills ()
 
Shape3D stroke (int col)
 
Shape3D stroke (int col, int parts)
 
int[] strokes ()
 
Shape3D strokeWeight (float weight)
 
Shape3D strokeWeight (float weight, int parts)
 
float[] strokeWeights ()
 
Shape3D scale (float scale)
 
float scale ()
 
Shape3D movie (PApplet pApplet, PImage movie)
 
Shape3D movie (PApplet pApplet, PImage movie, int parts)
 
Shape3D texture (PApplet app, String filename)
 
Shape3D texture (PImage texture)
 
Shape3D texture (PApplet app, String filename, int parts)
 
Shape3D texture (PImage texture, int parts)
 
PImage[] textures ()
 
Shape3D uv (float u0, float u1, float v0, float v1)
 
Shape3D uv (float u0, float u1, float v0, float v1, int parts)
 
Shape3D uvt (TransformUV transformer)
 
Shape3D uvt (TransformUV transformer, int parts)
 
Shape3D uvwrap (int wrap)
 
Shape3D uvwrap (int wrap, int parts)
 
Shape3D mesh (int nbrColSlices, int nbrRowSlices)
 
Shape3D mesh (int nbrColSlices, int nbrRowSlices, int parts)
 
Shape3D visible (boolean visible)
 
Shape3D visible (boolean visible, int parts)
 
boolean[] visibles ()
 
Shape3D moveTo (PVector pos)
 
Shape3D moveTo (float x, float y, float z)
 
Shape3D moveTo (float[] xyz)
 
float x ()
 
float y ()
 
float z ()
 
PVector getPosVec ()
 
PVector getPosVec (PVector target)
 
float[] getPosArray ()
 
float[] getPosArray (float[] target)
 
PVector getRotVec ()
 
PVector getRotVec (PVector target)
 
float[] getRotArray ()
 
float[] getRotArray (float[] target)
 
Shape3D rotateTo (PVector angles)
 
Shape3D rotateTo (float[] angles)
 
Shape3D rotateTo (float x, float y, float z)
 
Shape3D rotateToX (float x)
 
Shape3D rotateToY (float y)
 
Shape3D rotateToZ (float z)
 
Shape3D rotateBy (float x, float y, float z)
 
Shape3D rotateBy (float[] angle)
 
Shape3D rotateBy (PVector angles)
 
Shape3D rotateByX (float x)
 
Shape3D rotateByY (float y)
 
Shape3D rotateByZ (float z)
 
void draw (PGraphics pg)
 
void drawPickBuffer (PGraphics pg)
 

Static Public Member Functions

static void showSurfaceNormals ()
 
static void showSurfaceNormals (int color, float weight, float length)
 
static void hideSurfaceNormals ()
 
static int nextPickColor ()
 
static Picked pick (PApplet app, PGraphics canvas, int x, int y)
 
static Picked[] pick (PApplet app, PGraphics canvas, int x0, int y0, int x1, int y1)
 
static Picked[] mergePicks (Picked[] picked)
 
static void keepPickBufferImage (boolean keep)
 
static PImage pickBufferImage ()
 
static int nbrShapes3D ()
 

Public Attributes

String tag
 
int tagNo = 0
 
- Public Attributes inherited from shapes3d.utils.SConstants
int WIRE = 0x00000011
 
int SOLID = 0x00000012
 
int TEXTURE = 0x00000014
 
int DRAWALL = WIRE | SOLID | TEXTURE
 
int WHITE = 0xFFFFFFFF
 
int BLACK = 0xFF000000
 
int GREY = 0xFFC0C0C0
 
int RED = 0xFFFF0000
 
int GREEN = 0xFF00FF00
 
int BLUE = 0xFF0000FF
 
int YELLOW = 0xFFFFFF00
 
int PURPLE = 0xFFFF00FF
 
int CYAN = 0xFF00FFFF
 
int ORANGE = 0xFFFFC000
 
int CW = 1
 
int CCW = 2
 
int ALL = 0b11111111
 
int BOTTOM = 0b00000001
 
int TOP = 0b00000010
 
int FRONT = 0b00000100
 
int BACK = 0b00001000
 
int LEFT = 0b00010000
 
int RIGHT = 0b00100000
 
int BODY = 0b00000001
 
int END0 = 0b00000010
 
int END1 = 0b00000100
 
float ONE_DEG_T = (float) (Math.PI / 180.0)
 
PathOrthogonal ORTHO_X = new PathOrthogonal.PathNormalX()
 
PathOrthogonal ORTHO_Y = new PathOrthogonal.PathNormalY()
 
PathOrthogonal ORTHO_Z = new PathOrthogonal.PathNormalZ()
 
PathOrthogonal ORTHO_A = new PathOrthogonal.PathNormalAMC()
 
TransformUV ROT_0 = TransformUV.ROT0
 
TransformUV ROT_90 = TransformUV.ROT90
 
TransformUV ROT_180 = TransformUV.ROT180
 
TransformUV ROT_270 = TransformUV.ROT270
 
TransformUV FLIP_H = TransformUV.FLIPH
 
TransformUV FLIP_V = TransformUV.FLIPV
 
Rotation ROTATION_ZERO = new Rotation()
 
int T_BOX = 0x1001
 
int T_DOME = 0x1002
 
int T_CONE = 0x1003
 
int T_ELLIPSOID = 0x1004
 
int T_EXTRUSION = 0x1005
 
int T_LATHESTOCK = 0x1006
 
int T_MD2 = 0x1007
 
int T_SKYBOX = 0x1008
 
int T_SKYDOME = 0x1009
 
int T_TERRAIN = 0x100A
 
int T_TUBE = 0x100B
 
int C_LATHESURFACE = 0x2001
 
int C_OVAL = 0x2002
 
int C_POLYGON = 0x2003
 
int P_BCURVE2D = 0x3001
 
int P_BCURVE3D = 0x3002
 
int P_BSPLINE2D = 0x3003
 
int P_BSPLINE3D = 0x3004
 
int P_LINEAR = 0x3005
 
int P_LISSAJOUS = 0x3006
 
int P_RING = 0x3007
 
int P_SPIRAL = 0x3008
 

Protected Member Functions

abstract void calcShape ()
 
abstract void makeParts ()
 
abstract void releaseMemory ()
 
void fireEvent (Object...objects)
 

Protected Attributes

PGraphics on_canvas
 
PMatrix on_canvas_matrix
 
PVector pos = new PVector(0,0,0)
 
PVector rot = new PVector(0,0,0)
 
PVector up = new PVector(0,1,0)
 
PVector centreRot = new PVector(0,0,0)
 
float shapeScale = 1.0f
 
_ShapePart[] shapeParts = new _ShapePart[0]
 
int useParts = ALL
 
int pickColor
 
boolean pickable = true
 
Object eventHandlerObject = null
 
Method eventHandlerMethod = null
 
String eventHandlerMethodName
 

Static Protected Attributes

static HashMap< Integer, Shape3DmapColor2Shape = new HashMap<Integer, Shape3D>()
 
static HashMap< PGraphics,
PGraphics > 
mapCanvas2ColorBuffer = new HashMap<PGraphics, PGraphics>()
 
static List< Shape3DshapesMade = new ArrayList<Shape3D>()
 
static Set< PickedmarqueeSelection = new HashSet<Picked>()
 
static boolean show_normals = false
 
static int normal_color = 0xFFFF00FF
 
static float normal_weight = 1.0f
 
static float normal_length = 10
 
static int nextPickColor = 0xFF000000
 
static boolean keepCopy = false
 
static PImage pbImage = null
 

Detailed Description

This is the base class for all 3D shapes.
Each shape may consist of 1-8 parts, for instance the

  • Box has 6 parts, the 6 sides
  • Cone has 2 parts, 2 half cones (top and bottom)
  • Ellipsoid has 1 part, the main body
  • Extrusion has 3 parts the main body and the 2 end caps.
  • Tube has 3 parts the main body and the 2 end caps.
  • LatheStock has 3 parts the rotated surface and the 2 end caps.

So when shape picking it is not only possible to detect which shape is picked but also the actual part.

Author
Peter Lager

Constructor & Destructor Documentation

shapes3d.Shape3D.Shape3D ( )

All child classes should call this constructor.

Member Function Documentation

void shapes3d.Shape3D.addPickHandler ( Object  obj,
String  methodName 
)

Attempt to create the default pick event handler for this shape. The default event handler is a method that returns void and has a single parameter of the same type as the control class generating the event and a method name specific for that class.

Parameters
objthe object to handle the event
methodNamethe method to execute in the object handler class
Shape3D shapes3d.Shape3D.drawMode ( int  mode)

The draw mode can be either
S3D.SOLID - solid color as set with fill() method
S3D.WIRE - wire frame colour and wire thickness set with stroke() and strokeWeight() methods
S3D.TEXTURE - an image or movie is used to fill the shape
or any combination by or'ing them together e.g. S3D.SOLID | S3D.WIRE
Sets the drawing mode for all parts of the shape.

Parameters
modethe draw mode
Returns
this shape
Shape3D shapes3d.Shape3D.drawMode ( int  mode,
int  parts 
)

The draw mode can be either
S3D.SOLID - solid color as set with fill() method
S3D.WIRE - wire frame colour and wire thickness set with stroke() and strokeWeight() methods
S3D.TEXTURE - an image or movie is used to fill the shape
or any combination by or'ing them together e.g. S3D.SOLID | S3D.WIRE
Sets the drawing mode for the specified parts of the shape.

Parameters
modethe draw mode
partsthe parts to be textured
Returns
this shape
int [] shapes3d.Shape3D.drawModes ( )

Get an array of the draw modes for the shape parts.

Returns
an array of the draw modes for the shape parts
Shape3D shapes3d.Shape3D.fill ( int  col)

Set the fill color for all the shape parts.

Parameters
colthe color to use
Returns
this shape
Shape3D shapes3d.Shape3D.fill ( int  col,
int  parts 
)

Set the fill color for the specified shape parts.

Parameters
colthe color to use
partsthe parts affected
Returns
this shape
int [] shapes3d.Shape3D.fills ( )
Returns
an array of the fill colors for the shape parts.
void shapes3d.Shape3D.fireEvent ( Object...  objects)
protected

Attempt to fire an event for this control.

The method called must have a single parameter which is the object firing the event. If the method to be called is to have different parameters then it should be overridden in the child class The method

float [] shapes3d.Shape3D.getPosArray ( )
Returns
the current position as an array.
float [] shapes3d.Shape3D.getPosArray ( float[]  target)

Get the current position as an array.
If target is not null it is used to store the current position.

Parameters
targetuse this object to store position
Returns
the updated position
PVector shapes3d.Shape3D.getPosVec ( )
Returns
the current position as a PVector
PVector shapes3d.Shape3D.getPosVec ( PVector  target)

Get the current rotations as a PVector

Parameters
targetuse this object to store position
Returns
the updated position
float [] shapes3d.Shape3D.getRotArray ( )
Returns
the current rotations as an array.
float [] shapes3d.Shape3D.getRotArray ( float[]  target)

Get the current rotations as an array.
If target is not null it is used to store the current position.

Parameters
targetuse this object to store rotations
Returns
the three orthogonal angles
PVector shapes3d.Shape3D.getRotVec ( )
Returns
the current rotations as a PVector
PVector shapes3d.Shape3D.getRotVec ( PVector  target)

Get the current rotations as a PVector

Parameters
targetuse this object to store rotations
Returns
the three orthogonal angles
static void shapes3d.Shape3D.keepPickBufferImage ( boolean  keep)
static

Shapes3D can keep an image of the last pick buffer. This is useful for debugging but should not be used otherwise because it use significant processor time.

Parameters
keeptrue if we want to keep a copy of the buffer
static Picked [] shapes3d.Shape3D.mergePicks ( Picked[]  picked)
static

This method accepts an array of Picked objects, possibly from a marquee selection and merge the results so that each pick object is for a unique shape and the part flag will indicate all the parts selected for that object.
The original Picked object array is unchanged.

Parameters
pickedthe array of picked objects (1 for each part picked)
Returns
an array of picked objects (1 for each shape)
Shape3D shapes3d.Shape3D.moveTo ( PVector  pos)

Sets the shape's current position.

Parameters
posthe new position
Returns
this shape
Shape3D shapes3d.Shape3D.moveTo ( float  x,
float  y,
float  z 
)

Sets the shape's current position.

Parameters
xx coordinate
yy coordinate
zz coordinate
Returns
this shape
Shape3D shapes3d.Shape3D.moveTo ( float[]  xyz)

Sets the shape's current position.
Position is unchanged if the parameter array has less than 3 elements.

Parameters
xyzthe [xyz] coordinates
Returns
this shape
Shape3D shapes3d.Shape3D.movie ( PApplet  pApplet,
PImage  movie 
)

Use a processing.video.Movie object as a texture for all parts of this shape.

Parameters
pAppletthe enclosing PApplet object
moviethe movie to use as a texture
Returns
this shape
Shape3D shapes3d.Shape3D.movie ( PApplet  pApplet,
PImage  movie,
int  parts 
)

Use a processing.video.Movie object as a texture for the specified parts of this shape.

Parameters
pAppletthe enclosing PApplet object
moviethe movie to use as a texture
partsthe parts affected
Returns
this shape
int shapes3d.Shape3D.nbrParts ( )

Get the number of parts created for this shape

Returns
the number of shape parts in this shape
static int shapes3d.Shape3D.nbrShapes3D ( )
static

Return the number of shapes created so far.

Returns
the next shape number to use
static Picked shapes3d.Shape3D.pick ( PApplet  app,
PGraphics  canvas,
int  x,
int  y 
)
static

Will find the shape nearest to the viewer that is drawn at the given pixel position.
The user must specify the drawing canvas to use.

Parameters
appallows access to Processing methods / functions
canvasthe canvas to use
xx position to test
yy position to test
Returns
a Picked object with details of the shape picked or null if no shape is drawn at the given position.
static Picked [] shapes3d.Shape3D.pick ( PApplet  app,
PGraphics  canvas,
int  x0,
int  y0,
int  x1,
int  y1 
)
static

Will find all shapes that are visible in a rectangular area of the canvas. The area is defined by any two diagonally opposed corners.

Parameters
appallows access to Processing methods / functions
canvasthe canvas to use
x0horizontal position of a corner 0 of the selection area
y0vertical position of a corner 0 of the selection area
x1horizontal position of a corner 1 of the selection area
y1vertical position of a corner 1 of the selection area
compthe comparator used to sort the pick results.
Returns
an ordered array of shapes/parts visible in the selection aea
Shape3D shapes3d.Shape3D.pickable ( boolean  pickable)

Determines whether this shape can be picked. If false then shapes behind this shape can be picked instead.

Parameters
pickableif true this shape can be picked
Returns
this shape
boolean shapes3d.Shape3D.pickable ( )

Is this shape pickable

Returns
true if this shape is pickable
static PImage shapes3d.Shape3D.pickBufferImage ( )
static

Get a copy of the last pick buffer used. If you want to use this facility then enable it with the keepPickBufferImage(boolean) method.

Returns
null if no image exists else a copy of the pickbuffer
Shape3D shapes3d.Shape3D.rotateBy ( float  x,
float  y,
float  z 
)

Rotate shape from its current rotation state by the specified angles (radians)

Parameters
xadd this angle to the current x rotation angle
yadd this angle to the current y rotation angle
zadd this angle to the current z rotation angle
Returns
this shape
Shape3D shapes3d.Shape3D.rotateBy ( float[]  angle)

Rotate shape from its current rotation state by the specified angles (radians) in the array.
Ignored if the array has less than 3 elements.

Parameters
anglean array of relative angles
Returns
this shape
Shape3D shapes3d.Shape3D.rotateBy ( PVector  angles)

Rotate shape from its current rotation state by the specified angles (radians) in the PVector.

Parameters
anglesa PVector containing the XYZ relative angles
Returns
this shape
Shape3D shapes3d.Shape3D.rotateByX ( float  x)

Change the rotation about the x axis by the specified amount.

Parameters
xthe angle in radians
Returns
this shape
Shape3D shapes3d.Shape3D.rotateByY ( float  y)

Change the rotation about the y axis by the specified amount.

Parameters
ythe angle in radians
Returns
this shape
Shape3D shapes3d.Shape3D.rotateByZ ( float  z)

Change the rotation about the z axis by the specified amount.

Parameters
zthe angle in radians
Returns
this shape
Shape3D shapes3d.Shape3D.rotateTo ( PVector  angles)

Set the current rotations.

Parameters
anglesa PVector containing the x/y/z rotations in radians.
Returns
this shape
Shape3D shapes3d.Shape3D.rotateTo ( float[]  angles)

Set the current rotations. Ignored if the array has less than 3 elements.

Parameters
anglesan array containing the x/y/z rotations in radians.
Returns
this shape
Shape3D shapes3d.Shape3D.rotateTo ( float  x,
float  y,
float  z 
)

Set the current rotations.

Parameters
xrotation about x axis
yrotation about y axis
zrotation about z axis
Returns
this shape
Shape3D shapes3d.Shape3D.rotateToX ( float  x)

Set the rotation about the x axis

Parameters
xthe angle in radians
Returns
this shape
Shape3D shapes3d.Shape3D.rotateToY ( float  y)

Set the rotation about the y axis

Parameters
ythe angle in radians
Returns
this shape
Shape3D shapes3d.Shape3D.rotateToZ ( float  z)

Set the rotation about the z axis

Parameters
zthe angle in radians
Returns
this shape
Shape3D shapes3d.Shape3D.scale ( float  scale)

Set the scale for this shape

Parameters
scalethe scale to be used for the rendered shape
Returns
this shape
float shapes3d.Shape3D.scale ( )
Returns
the rendering scale for this shape
Shape3D shapes3d.Shape3D.stroke ( int  col)

Set the stroke color for all the shape parts

Parameters
colthe color to use
Returns
this shape
Shape3D shapes3d.Shape3D.stroke ( int  col,
int  parts 
)

Set the stroke color for the specified shape parts

Parameters
colthe color to use
partsthe parts affected
Returns
this shape
int [] shapes3d.Shape3D.strokes ( )
Returns
an array of the stroke colors for the shape parts.
Shape3D shapes3d.Shape3D.strokeWeight ( float  weight)

Set the stroke weight for all the shape parts

Parameters
weightthe stroke weight to use
Returns
this shape
Shape3D shapes3d.Shape3D.strokeWeight ( float  weight,
int  parts 
)

Set the stroke weight for all the shape parts

Parameters
weightthe stroke weight to use
partsthe parts affected
Returns
this shape
float [] shapes3d.Shape3D.strokeWeights ( )

Get an array of the stroke weights for the shape parts.

Returns
an array of the stroke weights applied to the shape parts
Shape3D shapes3d.Shape3D.tag ( String  tag)

Set the tag to be used for all parts.

Parameters
tagthe tag the descriptor string
Returns
this shape
Shape3D shapes3d.Shape3D.tag ( String  tag,
int  parts 
)

Set the tag for all the specified parts.

Parameters
tagthe descriptor string
partsthe parts affected
Returns
this shape
String [] shapes3d.Shape3D.tags ( )

Get an array of the tags for the shape parts.

Returns
an array holding the tags of the shape parts
Shape3D shapes3d.Shape3D.texture ( PApplet  app,
String  filename 
)

Use a processing.core.PImage object as a texture for all parts of this shape.

Parameters
appthe enclosing PApplet object
filenamethe image filename
Returns
this shape
Shape3D shapes3d.Shape3D.texture ( PImage  texture)

Use a processing.core.PImage object as a texture for all parts of this shape.

Parameters
texturethe PImage to use as the texture
Returns
this shape
Shape3D shapes3d.Shape3D.texture ( PApplet  app,
String  filename,
int  parts 
)

Use a processing.core.PImage object as a texture for the specified parts of this shape.

Parameters
pAppletthe enclosing PApplet object
filenamethe image filename
partsthe parts to be textured
Returns
this shape
Shape3D shapes3d.Shape3D.texture ( PImage  texture,
int  parts 
)

Use a processing.core.PImage object as a texture for the specified parts of this shape.

Parameters
texturethe PImage to use as the texture
partsthe parts to be textured
Returns
this shape
PImage [] shapes3d.Shape3D.textures ( )
Returns
an array of the textures used for the shape parts.
Shape3D shapes3d.Shape3D.use ( int  parts_to_use)

The following methods
drawMode, fill, stroke, strokeWeight, visible, texture, movie, uv
have two versions, the two parameter version

method_name(value, parts) 

where the first parameter is the value to apply and the second specifies which shape parts to apply the value to.
The second version has just a single parameter

method_name(value) 

where the parameter is the value to apply. By default this value will be applied to all the shape parts.
This method allows you to specify which parts should be modified with this version of the method.
To revert back to the original default behaviour call

 shape.use(S3D.ALL); 
Parameters
parts_to_usethe shape parts modified in the single parameter method
Returns
this shape
Shape3D shapes3d.Shape3D.uv ( float  u0,
float  u1,
float  v0,
float  v1 
)

Set the texture coordinates for all shape parts.

Parameters
u0horizontal texture coordinate
u1horizontal texture coordinate
v0vertical texture coordinate
v1vertical texture coordinate
Returns
this shape
Shape3D shapes3d.Shape3D.uv ( float  u0,
float  u1,
float  v0,
float  v1,
int  parts 
)

Set the texture coordinates for the specified shape parts.

Parameters
u0horizontal texture coordinate
u1horizontal texture coordinate
v0vertical texture coordinate
v1vertical texture coordinate
partsthe parts to be affected
Returns
this shape
Shape3D shapes3d.Shape3D.uvt ( TransformUV  transformer)

Use this to transform the UV coordinates for all parts.

Parameters
transformerthe UV transformation to apply
Returns
this shape
Shape3D shapes3d.Shape3D.uvt ( TransformUV  transformer,
int  parts 
)

Use this to transform the UV coordinates for the specified parts.

Parameters
transformerthe UV transformation to apply
partscombined part flags
Returns
this shape
Shape3D shapes3d.Shape3D.uvwrap ( int  wrap)

Use this to decide whether the texture is repeated or clamped.
The parameter must be either REPEAT or CLAMP, any other value will be ignored.

Parameters
wrapREPEAT or CLAMP
Returns
this shape
Shape3D shapes3d.Shape3D.uvwrap ( int  wrap,
int  parts 
)

Use this to decide whether the texture is repeated or clamped for the specified parts.
The parameter must be either REPEAT or CLAMP, any other value will be ignored.

Parameters
wrapREPEAT or CLAMP
partscombined part flags
Returns
this shape
Shape3D shapes3d.Shape3D.visible ( boolean  visible)

Makes all shape parts visible or invisible.

Parameters
visibletrue if you want to see this shape
Returns
this shape
Shape3D shapes3d.Shape3D.visible ( boolean  visible,
int  parts 
)

Makes the specified shape parts visible or invisible.

Parameters
visibletrue if you want to see this shape
partscombined part flags
Returns
this shape
boolean [] shapes3d.Shape3D.visibles ( )
Returns
an array of booleans representing the visibility state of the shape parts.

Member Data Documentation

String shapes3d.Shape3D.tag

User defined tag for this shape.
This can be any text the user likes or finds useful. When a shape is created this is initialised to the name of the class e.g. Toroid, Cone etc.

int shapes3d.Shape3D.tagNo = 0

User defined tag number.
This can be any number the user likes or finds useful.


The documentation for this class was generated from the following file: