Skip to content

jdf/patchy

Repository files navigation

Patchy provides an easy-to-use bicubic patch for 3D graphics in the Processing programming environment.

For a demo, and installation instructions, please see the Patchy home page.

import patchy.*;

// a 4x4 array of control points for the bicubic surface
PVector[][] controlPoints = getControlPoints();
Patch patch = Patch.create(Patch.BEZIER, controlPoints);
// or Patch.BSPLINE, Patch.HERMITE, Patch.CATMULL_ROM
void draw() {
   //  animate the Y-value of a control point
   patch.setY(2, 0, 30 * cos(frameRate/40f));

   fill(255, 100, 100);
   noStroke();
   patch.draw(this);
}

Acknowledgements

I learned how to calculate bicubic surfaces by reading the course material that Ken Perlin so kindly provides. Part of Patchy is based on his code, and I am very grateful for it.

I learned how to calculate vertex normals, and how to choose vertexes for triangles when rendering, by studying this code, by Tomasz Kaczmarzyk (tom3k). Tomasz was kind enough to explicitly license that code under the Apache 2.0 license, so that I could freely share my work. Thank you, tom3k.

Patch Types (Basis Matrices)

Patchy.BEZIER
Patchy.BSPLINE
Patchy.CATMULL_ROM
Patchy.HERMITE

Constructing a Patch or PatchGroup

// control points as a 4x4 matrix of PVectors
Patch.create(double[][] basis, PVector[][] controlPoints, int gridSteps);
Patch.create(double[][] basis, PVector[][] controlPoints);  // default 20 grid steps

// control points as three 4x4 matrices of x, y, and z coordinates
Patch.create(double[][] basis,
             double[][] cpX, double[][] cpY, double[][] cpZ,
             int gridSteps);
Patch.create(double[][] basis,
             double[][] cpX, double[][] cpY, double[][] cpZ);

// the same but with floats, which are more Processing-friendly
Patch.create(double[][] basis,
             float[][] cpX, float[][] cpY, float[][] cpZ,
             int gridSteps);
Patch.create(double[][] basis,
             float[][] cpX, float[][] cpY, float[][] cpZ);

PatchGroup group = new PatchGroup();
group.add(p1);
group.add(p2);

Drawing a Patch or PatchGroup

void draw(PApplet p); // uses current stroke, fill, and transforms
void drawControlPoints(PApplet p);  // useful for debugging

Other Useful Methods on Patch and PatchGroup

BoundingVolume getBounds();  // for figuring out scale and position
BoundingVolume scale(double s); // scales the patch or group in-place
void translate(double dx, double dy,
   double dz);  // translates the patch or group in-place
void setBasis(double[][] basisMatrix);
void setGridSteps(int steps); // change the resolution of the rendered mesh

Methods on Patch (but not !PatchGroup)

void set(int row, int col, double xVal, double yVal, double zVal);
void set(int row, int col, PVector p);
void setX(int row, int col, double val);
void setY(int row, int col, double val);
void setZ(int row, int col, double val);

// set the number of vertices created when rendering patch as triangles
void setGridSteps(int gridSteps);

Are you looking for the “Patchy” extension to the Mantis bug-tracking system?
That’s on sourceforge.

About

Patchy provides an easy-to-use bicubic patch for 3D graphics in the Processing programming environment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published