Super Ellipsoid Mesh Builder
original example by Karsten Schmidt,
Toxiclibs ported to js by Kyle Phillips
Usage:
- w: toggle wireframe on/off
- n: toggle normal vector display on/off
SuperEllipsoidMeshBuilder demonstrates how to use the SurfaceMeshBuilder
class in conjunction with a SuperEllipsoid function to dynamically create a
variety of useful geometric forms. It also demonstrates using
toxi.processing.ToxiclibsSupport
for crossmode support between Processing and Processing.js.
The super ellipsoid is described in detail on Paul Bourke’s website.
In this demo 2 out-of-sync sine waves are used to animate
the ellipsoid parameters. Included is also a re-usable function for displaying
a generic TriangleMesh instance, incl. the display of surface normals useful for
debug purposes.
var TriangleMesh = toxi.geom.mesh.TriangleMesh,
ToxiclibsSupport = toxi.processing.ToxiclibsSupport,
SurfaceMeshBuilder = toxi.geom.mesh.SurfaceMeshBuilder,
SuperEllipsoid = toxi.geom.mesh.SuperEllipsoid,
SineWave = toxi.math.waves.SineWave,
Vec3D = toxi.geom.Vec3D;
TriangleMesh mesh = new TriangleMesh();
AbstractWave modX, modY;
ToxiclibsSupport gfx;
boolean isWireFrame;
boolean showNormals;
void setup() {
size(940,480, OPENGL);
gfx = new ToxiclibsSupport(this);
isWireFrame = true;
modX = new SineWave(0, 0.01f, 2.5f, 2.5f);
modY = new SineWave(PI, 0.017f, 2.5f, 2.5f);
}
void draw() {
SurfaceFunction functor=new SuperEllipsoid(modX.update(), modY.update());
SurfaceMeshBuilder b = new SurfaceMeshBuilder(functor);
mesh = (TriangleMesh)b.createMesh(new TriangleMesh("se"+frameCount),20, 80);
mesh.computeVertexNormals();
background(0);
lights();
translate(width / 2, height / 2, 0);
rotateX(mouseY * 0.01);
rotateY(mouseX * 0.01);
gfx.origin(300);
if (isWireFrame) {
noFill();
stroke(255);
}
else {
fill(255);
noStroke();
}
gfx.origin(300);
if (isWireFrame) {
noFill();
stroke(255);
}
else {
fill(255);
noStroke();
}