# HG changeset patch
# User postspectacular
# Date 1327488349 0
# Node ID 91ff272b669d94722ae34f5bc6241a24186a59b9
# Parent 5acdef0df9f6225c20b10907fd05fd1fc123d219
updating P5 examples with API changes and adding MeshAlignToTriangle example
diff -r 5acdef0df9f6225c20b10907fd05fd1fc123d219 -r 91ff272b669d94722ae34f5bc6241a24186a59b9 examples/core/mesh/MeshAlignToTriangle/MeshAlignToTriangle.pde
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/core/mesh/MeshAlignToTriangle/MeshAlignToTriangle.pde Wed Jan 25 10:45:49 2012 +0000
@@ -0,0 +1,56 @@
+import toxi.geom.*;
+import toxi.geom.mesh.*;
+import toxi.processing.*;
+
+import processing.opengl.*;
+
+Triangle3D tri;
+TriangleMesh mesh;
+ToxiclibsSupport gfx;
+
+void setup() {
+ size(400, 400, OPENGL);
+ gfx=new ToxiclibsSupport(this);
+ randomize();
+}
+
+void draw() {
+ background(0);
+ lights();
+ translate(width/2, height/2, 0);
+ rotateX(mouseY*0.01);
+ rotateY(mouseX*0.01);
+ // draw world space axes
+ gfx.origin(300);
+ // get triangle center and visualize normal vector
+ Vec3D c=tri.computeCentroid();
+ stroke(255, 0, 255);
+ gfx.line(c, c.add(tri.computeNormal().scale(300)));
+ noStroke();
+ // draw triangle & mesh
+ fill(255, 255, 0);
+ gfx.triangle(tri);
+ fill(0, 255, 255);
+ gfx.mesh(mesh);
+}
+
+void randomize() {
+ // create random triangle
+ tri=new Triangle3D(
+ Vec3D.randomVector().scale(100),
+ Vec3D.randomVector().scale(100),
+ Vec3D.randomVector().scale(100)
+ );
+ // create box mesh around origin
+ mesh = (TriangleMesh)new AABB(50).toMesh();
+ // get triangle normal
+ Vec3D n=tri.computeNormal();
+ // rotate mesh such that the +Z axis is aligned with the triangle normal
+ mesh.pointTowards(n);
+ // move box in the normal direction 100 units relative from the triangle center
+ mesh.translate(tri.computeCentroid().add(n.scale(100)));
+}
+
+void keyPressed() {
+ if (key=='r') randomize();
+}
diff -r 5acdef0df9f6225c20b10907fd05fd1fc123d219 -r 91ff272b669d94722ae34f5bc6241a24186a59b9 examples/physics/CrashTest/CrashTest.pde
--- a/examples/physics/CrashTest/CrashTest.pde Wed Jan 25 10:36:22 2012 +0000
+++ b/examples/physics/CrashTest/CrashTest.pde Wed Jan 25 10:45:49 2012 +0000
@@ -28,17 +28,18 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
+import processing.opengl.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.physics3d.*;
import toxi.physics3d.behaviors.*;
import toxi.processing.*;
-import processing.opengl.*;
ToxiclibsSupport gfx;
VerletPhysics3D physics;
-WETriangleMesh box;
+WETriangleMesh mesh;
void setup() {
size(680, 382, OPENGL);
@@ -49,11 +50,11 @@
void draw() {
physics.update();
// update mesh vertices based on the current particle positions
- for (Vertex v : box.vertices.values()) {
+ for (Vertex v : mesh.vertices.values()) {
v.set(physics.particles.get(v.id));
}
// update mesh normals
- box.computeFaceNormals();
+ mesh.computeFaceNormals();
// setup lighting
background(51);
lights();
@@ -61,7 +62,7 @@
specular(255);
shininess(16);
// point camera at mesh centroid
- Vec3D c = box.computeCentroid();
+ Vec3D c = mesh.computeCentroid();
camera(-100, -50, 80, c.x, c.y, c.z, 0, 1, 0);
// draw coordinate system
gfx.origin(new Vec3D(), 50);
@@ -72,31 +73,31 @@
// draw car
fill(160);
noStroke();
- gfx.mesh(box, false, 0);
+ gfx.mesh(mesh, false, 0);
}
void initPhysics() {
physics = new VerletPhysics3D();
- box = new WETriangleMesh().addMesh(new STLReader().loadBinary(openStream("audi.stl"),"car",STLReader.WEMESH));
+ mesh = new WETriangleMesh().addMesh(new STLReader().loadBinary(openStream("audi.stl"),"car",STLReader.WEMESH));
// properly orient and scale mesh
- box.rotateX(HALF_PI);
- box.scale(8);
+ mesh.rotateX(HALF_PI);
+ mesh.scale(8);
// adjust physics bounding box based on car (but bigger)
// and align car with bottom of the new box
- AABB bounds = box.getBoundingBox();
+ AABB bounds = mesh.getBoundingBox();
Vec3D ext = bounds.getExtent();
Vec3D min = bounds.sub(ext.scale(4, 3, 2));
Vec3D max = bounds.add(ext.scale(4, 3, 2));
physics.setWorldBounds(AABB.fromMinMax(min, max));
- box.translate(new Vec3D(ext.scale(3, 2, 0)));
+ mesh.translate(new Vec3D(ext.scale(3, 2, 0)));
// set gravity along negative X axis with slight downward
physics.addBehavior(new GravityBehavior3D(new Vec3D(-0.1f, 0.001f, 0)));
// turn mesh vertices into physics particles
- for (Vertex v : box.vertices.values()) {
+ for (Vertex v : mesh.vertices.values()) {
physics.addParticle(new VerletParticle3D(v));
}
// turn mesh edges into springs
- for (WingedEdge e : box.edges.values()) {
+ for (WingedEdge e : mesh.edges.values()) {
VerletParticle3D a = physics.particles.get(((WEVertex) e.a).id);
VerletParticle3D b = physics.particles.get(((WEVertex) e.b).id);
physics.addSpring(new VerletSpring3D(a, b, a.distanceTo(b), 1f));
diff -r 5acdef0df9f6225c20b10907fd05fd1fc123d219 -r 91ff272b669d94722ae34f5bc6241a24186a59b9 examples/sim/CAShapeShift/CAShapeShift.pde
--- a/examples/sim/CAShapeShift/CAShapeShift.pde Wed Jan 25 10:36:22 2012 +0000
+++ b/examples/sim/CAShapeShift/CAShapeShift.pde Wed Jan 25 10:45:49 2012 +0000
@@ -61,7 +61,7 @@
// see javadocs for list of names:
// http://toxiclibs.org/docs/colorutils/toxi/color/NamedColor.html
grad.addColorAt(0,NamedColor.WHITE);
- grad.addColorAt(128,NamedColor.RED);
+ grad.addColorAt(rule.getStateCount(),NamedColor.RED);
// the tone map will map cell states/ages to a gradient color
toneMap=new ToneMap(0,rule.getStateCount()-1,grad);
frameRate(999);
diff -r 5acdef0df9f6225c20b10907fd05fd1fc123d219 -r 91ff272b669d94722ae34f5bc6241a24186a59b9 examples/volume/BoxFluidDemo/BoxFluidDemo.pde
--- a/examples/volume/BoxFluidDemo/BoxFluidDemo.pde Wed Jan 25 10:36:22 2012 +0000
+++ b/examples/volume/BoxFluidDemo/BoxFluidDemo.pde Wed Jan 25 10:45:49 2012 +0000
@@ -66,9 +66,9 @@
float isoThreshold=3;
int numP;
-VerletPhysics physics;
-ParticleConstraint boundingSphere;
-GravityBehavior gravity;
+VerletPhysics3D physics;
+ParticleConstraint3D boundingSphere;
+GravityBehavior3D gravity;
VolumetricSpaceArray volume;
IsoSurface surface;
@@ -108,7 +108,7 @@
strokeWeight(4);
stroke(0);
for(Iterator i=physics.particles.iterator(); i.hasNext();) {
- VerletParticle p=(VerletParticle)i.next();
+ VerletParticle3D p=(VerletParticle3D)i.next();
Vec3D col=p.add(colAmp).scaleSelf(0.5);
stroke(col.x,col.y,col.z);
point(p.x,p.y,p.z);
diff -r 5acdef0df9f6225c20b10907fd05fd1fc123d219 -r 91ff272b669d94722ae34f5bc6241a24186a59b9 examples/volume/BoxFluidDemo/Physics.pde
--- a/examples/volume/BoxFluidDemo/Physics.pde Wed Jan 25 10:36:22 2012 +0000
+++ b/examples/volume/BoxFluidDemo/Physics.pde Wed Jan 25 10:45:49 2012 +0000
@@ -1,12 +1,12 @@
void initPhysics() {
- physics=new VerletPhysics();
+ physics=new VerletPhysics3D();
physics.setWorldBounds(new AABB(new Vec3D(),new Vec3D(DIM,DIM,DIM)));
if (surface!=null) {
surface.reset();
mesh.clear();
}
boundingSphere=new SphereConstraint(new Sphere(new Vec3D(),DIM),SphereConstraint.INSIDE);
- gravity=new GravityBehavior(new Vec3D(0,1,0));
+ gravity=new GravityBehavior3D(new Vec3D(0,1,0));
physics.addBehavior(gravity);
}
@@ -17,25 +17,24 @@
gravity.setForce(grav.scaleSelf(2));
numP=physics.particles.size();
if (random(1)<0.8 && numP
Usage:
Usage: