• fullscreen
  • aLittleBitMore2_0.pde
  • panel.pde
  • particle.pde
  • //aLittleBitMore
    //echoechonoisenoise 2010
    //echo.link: this-yourWork-this
    
    import toxi.processing.*;
    import toxi.geom.mesh.*;
    import peasy.org.apache.commons.math.*;
    import peasy.*;
    import peasy.org.apache.commons.math.geometry.*;
    import toxi.geom.*;
    import toxi.geom.mesh.*;
    import toxi.volume.*;
    import processing.dxf.*;
    
    boolean record = false;
    boolean animate=true;
    WETriangleMesh mesh;
    int DIM=45;//dimensions of the voxel space: 45x45x45 voxels
    float ISO_THRESHOLD = 3;//higher values smoothen the result, lower uncover spherical characteristics of volumebrush
    Vec3D SCALE=new Vec3D(1,1,1).scaleSelf(1000);//proportions and scale of voxel space
    VolumetricSpace volume=new VolumetricSpaceArray(SCALE,DIM,DIM,DIM);
    ;
    IsoSurface surface;
    VolumetricBrush brush;
    float brushDensity=10;
    
    ArrayList ptc;//particles list
    int pAmount=300;
    ArrayList panels;//panels list
    float i=random(100);//position in noise space, randomized, so each time different form comes out
    float sc=0.008;
    
    PVector l[];//lights stored as vectors
    float str;
    int fcount=0;
    float atick=0;
    
    
    PeasyCam cam;
    
    void setup() {
      size(700,700,P3D);    
      stroke(0);
      strokeWeight(2.5);
      cam = new PeasyCam(this,450);
      cam.rotateX(PI*0.3);
      cam.rotateZ(PI*0.3);
      initLight();
    
    
      surface=new HashIsoSurface(volume);
      brush=new RoundBrush(volume,10);
      ptc=new ArrayList();
      for(int i=0;i<pAmount;i++) {
        ptc.add(new Particle());
      }
      panels=new ArrayList();
    }
    
    void draw() {
      background(35);
      for(int i=0; i<l.length; i++) {
        directionalLight(str,str,str, l[i].x,l[i].y,l[i].z);//all the lights
      }
      if (record == true) {
        beginRaw(DXF, "shapes/shape-####.dxf");
      }
      if(fcount<=30) {//record 30 steps as a shape, each time updating the isosurface
        volume.closeSides();  
        surface.reset();
        mesh = new WETriangleMesh();
        surface.computeSurfaceMesh(mesh,ISO_THRESHOLD);
        new LaplacianSmooth().filter(mesh, 1);
        for(int i=0;i<ptc.size();i++) {
          Particle c=(Particle)ptc.get(i);
          c.behave();//move particle around
          c.display();//draw it's trace using volumetric brush
        }
        panels.clear();
        int num=mesh.getNumFaces(); 
        Vec3D[] verts=null;
        for(int i=0; i<num; i++) {
          Face f=mesh.faces.get(i);
          PVector a=new PVector(f.a.x,f.a.y,f.a.z);
          PVector b=new PVector(f.b.x,f.b.y,f.b.z);
          PVector c=new PVector(f.c.x,f.c.y,f.c.z);
          panels.add(new TriangularPanel(a,b,c));
        }
      }
      for(int i=0;i<panels.size();i++) {
        TriangularPanel p=(TriangularPanel) panels.get(i);
        if(animate)p.construct();
        p.display();
      }
      if (record == true) {
        endRaw();
        record = false; // Stop recording to the file
      }
      fcount++;
      if(animate)atick+=0.01;
    }
    
    void keyPressed() {
      if(key=='a') {//move panels, change colors
        animate=!animate;
      }
      if(key==' ') {//reset all the stuff, and create a new shape
        fcount=0;
        atick=0;
        i=random(100);
        volume=new VolumetricSpaceArray(SCALE,DIM,DIM,DIM);  
        surface=new HashIsoSurface(volume); 
        brush=new RoundBrush(volume,10);
        ptc=new ArrayList();
        for(int i=0;i<pAmount;i++) {
          ptc.add(new Particle());
        }
      }
      if(key=='l') {//save to dxf
        new LaplacianSmooth().filter(mesh, 1);
        panels.clear();
        int num=mesh.getNumFaces(); 
        Vec3D[] verts=null;
        for(int i=0; i<num; i++) {
          Face f=mesh.faces.get(i);
          PVector a=new PVector(f.a.x,f.a.y,f.a.z);
          PVector b=new PVector(f.b.x,f.b.y,f.b.z);
          PVector c=new PVector(f.c.x,f.c.y,f.c.z);
          panels.add(new TriangularPanel(a,b,c));
        }
      }
    }
    
    void initLight() {//by Marius Watz
      randomSeed(11);
      l=new PVector[7];
      for(int i=0; i<l.length; i++) {
        str=random(TWO_PI);
        l[i]=new PVector(cos(str)*10,0.3,sin(str)*10);
      }
      str=random(120,180);
    }
    
    
    
    class TriangularPanel {
      PVector p1,p2,p3;//three input points
      PVector[] q_pts;//array of quarter parts of all the edges
      PVector centroid;
      PVector mid_p1p2,mid_p2p3,mid_p3p1,innP1,innP2,innP3;
      TriangularPanel(PVector _p1,PVector _p2,PVector _p3) {
        p1=_p1;
        p2=_p2;
        p3=_p3;
        q_pts=new PVector[6];
        construct();
      }
      void construct() {
        //middle points of each edge
        mid_p1p2=PVector.sub(p1,p2);
        mid_p1p2.normalize();    
        mid_p1p2.mult(p1.dist(p2)/2);
        mid_p1p2.add(p2);
    
        mid_p2p3=PVector.sub(p2,p3);
        mid_p2p3.normalize();    
        mid_p2p3.mult(p2.dist(p3)/2);
        mid_p2p3.add(p3);
    
        mid_p3p1=PVector.sub(p3,p1);
        mid_p3p1.normalize();    
        mid_p3p1.mult(p3.dist(p1)/2);
        mid_p3p1.add(p1);
        
        //triangle centroid
        centroid=PVector.sub(p2,mid_p3p1);
        centroid.normalize();    
        centroid.mult(p2.dist(mid_p3p1)*0.33);
        centroid.add(mid_p3p1);
        
        //scaling parameters
        float par1=noise(atick+centroid.x*sc,atick+centroid.y*sc,atick+centroid.z*sc);//regulates size of each panel
        float par2=noise(atick+centroid.x*sc,atick+centroid.y*sc,atick+centroid.z*sc);//regulates size of inner triangle 
    
        //further subdivision
        q_pts[0]=PVector.sub(p1,mid_p1p2);
        q_pts[0].normalize();    
        q_pts[0].mult(p1.dist(mid_p1p2)*par1);
        q_pts[0].add(mid_p1p2);
    
        q_pts[1]=PVector.sub(p2,mid_p1p2);
        q_pts[1].normalize();    
        q_pts[1].mult(p2.dist(mid_p1p2)*par1);
        q_pts[1].add(mid_p1p2);
    
        q_pts[2]=PVector.sub(p2,mid_p2p3);
        q_pts[2].normalize();    
        q_pts[2].mult(p2.dist(mid_p2p3)*par1);
        q_pts[2].add(mid_p2p3);
    
        q_pts[3]=PVector.sub(p3,mid_p2p3);
        q_pts[3].normalize();    
        q_pts[3].mult(p3.dist(mid_p2p3)*par1);
        q_pts[3].add(mid_p2p3);
    
        q_pts[4]=PVector.sub(p3,mid_p3p1);
        q_pts[4].normalize();    
        q_pts[4].mult(p3.dist(mid_p3p1)*par1);
        q_pts[4].add(mid_p3p1);
    
        q_pts[5]=PVector.sub(p1,mid_p3p1);
        q_pts[5].normalize();    
        q_pts[5].mult(p1.dist(mid_p3p1)*par1);
        q_pts[5].add(mid_p3p1);    
    
        //inner triangle points
        innP1=PVector.sub(centroid,mid_p1p2);
        innP1.normalize();    
        innP1.mult(centroid.dist(mid_p1p2)*par2);
        innP1.add(mid_p1p2);
    
        innP2=PVector.sub(centroid,mid_p2p3);
        innP2.normalize();    
        innP2.mult(centroid.dist(mid_p2p3)*par2);
        innP2.add(mid_p2p3);
    
        innP3=PVector.sub(centroid,mid_p3p1);
        innP3.normalize();    
        innP3.mult(centroid.dist(mid_p3p1)*par2);
        innP3.add(mid_p3p1);
      }
    
      void display() {
        fill(noise(atick+p1.x*sc,atick+p1.y*sc,atick+p1.z*sc)*255,50,255-noise(atick+p1.x*sc,atick+p1.y*sc,atick+p1.z*sc)*255);//regulates color of each segment
        beginShape();
        vertex(innP1.x,innP1.y,innP1.z);
        vertex(mid_p1p2.x,mid_p1p2.y,mid_p1p2.z);
        vertex(q_pts[0].x,q_pts[0].y,q_pts[0].z);
        vertex(q_pts[5].x,q_pts[5].y,q_pts[5].z);
        vertex(mid_p3p1.x,mid_p3p1.y,mid_p3p1.z);
        vertex(innP3.x,innP3.y,innP3.z);
        endShape(CLOSE);
        fill(noise(atick+p2.x*sc,atick+p2.y*sc,atick+p2.z*sc)*255,50,255-noise(atick+p2.x*sc,atick+p2.y*sc,atick+p2.z*sc)*255);//-||-
            beginShape();
        vertex(innP2.x,innP2.y,innP2.z);
        vertex(mid_p2p3.x,mid_p2p3.y,mid_p2p3.z);
        vertex(q_pts[2].x,q_pts[2].y,q_pts[2].z);
        vertex(q_pts[1].x,q_pts[1].y,q_pts[1].z);
        vertex(mid_p1p2.x,mid_p1p2.y,mid_p1p2.z);
        vertex(innP1.x,innP1.y,innP1.z);
        endShape(CLOSE);
        fill(noise(atick+p3.x*sc,atick+p3.y*sc,atick+p3.z*sc)*255,50,255-noise(atick+p3.x*sc,atick+p3.y*sc,atick+p3.z*sc)*255);//-||-
         beginShape();
        vertex(innP3.x,innP3.y,innP3.z);
        vertex(mid_p3p1.x,mid_p3p1.y,mid_p3p1.z);
        vertex(q_pts[4].x,q_pts[4].y,q_pts[4].z);
        vertex(q_pts[3].x,q_pts[3].y,q_pts[3].z);
        vertex(mid_p2p3.x,mid_p2p3.y,mid_p2p3.z);
        vertex(innP2.x,innP2.y,innP2.z);
        endShape(CLOSE);
        
      }
    }
    
    
    class Particle {
      Vec3D pos;//using toxi's Vec3D instead of PVector-VolumetricBrush requirements
      float speed;
      int spread=70;  
      Particle() {
        pos=new Vec3D(random(-spread,spread),random(-spread,spread),random(-spread,spread));
        speed=30;
      }
      void behave() {    
        pos.x+=(noise(i,pos.x*sc,pos.y*sc)-.5)*speed;
        pos.y+=(noise(i+1,pos.x*sc,pos.z*sc)-.5)*speed;
        pos.z+=(noise(i+2,pos.x*sc,pos.y*sc)-.5)*speed;
      }
      void display() {
        brush.drawAtAbsolutePos(pos,brushDensity);//drawing particle paths with volumetric brush
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    echoechonoisenoise
    guillaume
    11 Apr 2011
    Hello Echoes, first of all, all this scripts are great!
    I have the same problem on all your 3d scripts when i try to run them:
    Cannot instantiate the type volumetricSpace.
    i already have the last release of toxic lib
    Any idea?
    thx

    hey guillaume,
    thx. all of my volumetric stuff before noisenoise (the green one) uses old toxiclibs.
    i need to update them once i have some time. it's actually easy to fix it: just compare it with noisenoise code...cheers!
    just uploaded an updated version. added some smoothing action. "l" for more smoothing.
    guillaume
    11 Apr 2011
    !! thx
    You need to login/register to comment.