Java Code Examples for processing.core.PShape#fill()

The following examples show how to use processing.core.PShape#fill() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DwSoftGrid3D.java    From PixelFlow with MIT License 6 votes vote down vote up
private void displayGridXZ(PShape pg, float[][] normals, int iy, PGraphics2D tex){
  pg.beginShape(PConstants.TRIANGLE_STRIP);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(tex);
  pg.fill(material_color);
  int iz, ix;
  for(iz = 0; iz < nodes_z-1; iz++){
    for(ix = 0; ix < nodes_x; ix++){
      vertex(pg, getNode3D(ix, iy, iz+0), normals[(iz+0)*nodes_x+ix], ix * tx_inv, (iz+0) * tz_inv);
      vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], ix * tx_inv, (iz+1) * tz_inv);
    }
    ix -= 1; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], 0, 0);
    ix  = 0; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_x+ix], 0, 0);
  }
  pg.endShape();
}
 
Example 2
Source File: DwSoftGrid3D.java    From PixelFlow with MIT License 6 votes vote down vote up
private void displayGridYZ(PShape pg, float[][] normals, int ix, PGraphics2D tex){
  pg.beginShape(PConstants.TRIANGLE_STRIP);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(tex);
  pg.fill(material_color);
  int iz, iy;
  for(iz = 0; iz < nodes_z-1; iz++){
    for(iy = 0; iy < nodes_y; iy++){
      vertex(pg, getNode3D(ix, iy, iz+0), normals[(iz+0)*nodes_y+iy], iy * ty_inv, (iz+0) * tz_inv);
      vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_y+iy], iy * ty_inv, (iz+1) * tz_inv);
    }
    iy -= 1; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_y+iy], 0, 0);
    iy  = 0; vertex(pg, getNode3D(ix, iy, iz+1), normals[(iz+1)*nodes_y+iy], 0, 0);
  }
  pg.endShape();
}
 
Example 3
Source File: DwSoftGrid3D.java    From PixelFlow with MIT License 6 votes vote down vote up
private void displayGridXY(PShape pg, float[][] normals, int iz, PGraphics2D tex){
  pg.beginShape(PConstants.TRIANGLE_STRIP);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(tex);
  pg.fill(material_color);
  int ix, iy;
  for(iy = 0; iy < nodes_y-1; iy++){
    for(ix = 0; ix < nodes_x; ix++){
      vertex(pg, getNode3D(ix, iy+0, iz), normals[(iy+0)*nodes_x+ix], ix * tx_inv, (iy+0) * ty_inv);
      vertex(pg, getNode3D(ix, iy+1, iz), normals[(iy+1)*nodes_x+ix], ix * tx_inv, (iy+1) * ty_inv);
    }
    ix -= 1; vertex(pg, getNode3D(ix, iy+1, iz), normals[(iy+1)*nodes_x+ix], 0, 0);
    ix  = 0; vertex(pg, getNode3D(ix, iy+1, iz), normals[(iy+1)*nodes_x+ix], 0, 0);
  }
  pg.endShape();
}
 
Example 4
Source File: DwSoftGrid2D.java    From PixelFlow with MIT License 6 votes vote down vote up
private void displayGridXY(PShape pg, PGraphics2D tex){
  pg.beginShape(PConstants.TRIANGLE_STRIP);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(tex);
  pg.fill(material_color);
  pg.noStroke();
  int ix, iy;
  for(iy = 0; iy < nodes_y-1; iy++){
    for(ix = 0; ix < nodes_x; ix++){
      vertex(pg, getNode(ix, iy+0), ix * tx_inv, (iy+0) * ty_inv);
      vertex(pg, getNode(ix, iy+1), ix * tx_inv, (iy+1) * ty_inv);
    }
    ix -= 1; vertex(pg, getNode(ix, iy+1), 0, 0);
    ix  = 0; vertex(pg, getNode(ix, iy+1), 0, 0);
  }
  pg.endShape();
}
 
Example 5
Source File: PShapeUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void repairMissingSVGVertex(PShape shape) {
	PVector v1 = shape.getVertex(0);
	PVector v2 = shape.getVertex(0);
	PVector v3 = shape.getVertex(shape.getVertexCount() - 1);
	
	shape.beginShape();
	shape.fill(255, 255, 255);
	shape.noStroke();
	shape.vertex(v1.x, v1.y, v1.z);
	shape.vertex(v2.x, v2.y, v2.z);
	shape.vertex(v3.x, v3.y, v3.z);
	shape.endShape();
}
 
Example 6
Source File: Icosahedron.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape createIcosahedronGrouped(PApplet p, int level, PImage img, int fillColor, int strokeColor, float strokeWeight) {
	// the icosahedron is created with positions, normals and texture coordinates in the above class
	Icosahedron ico = new Icosahedron(level);
	p.textureMode(P.NORMAL); // set textureMode to normalized (range 0 to 1);
	PShape mesh = p.createShape(P.GROUP); // create the initial PShape
	
	
	// put all the vertices, uv texture coordinates and normals into the PShape
	PShape triangle = null;
	for (int i=0; i<ico.positions.size(); i++) {
		if(i % 3 == 0) {
			triangle = p.createShape();
			triangle.beginShape(P.TRIANGLE); // define the PShape type: TRIANGLES
			if(fillColor != -1) {
				triangle.strokeWeight(strokeWeight);
				triangle.stroke(strokeColor);
				triangle.fill(fillColor);
			}
			if(img != null) mesh.texture(img);
		}
		PVector pos = ico.positions.get(i);
		PVector t = ico.texCoords.get(i);
		PVector n = ico.normals.get(i);
		triangle.normal(n.x, n.y, n.z);
		triangle.vertex(pos.x, pos.y, pos.z, t.x, t.y);
		
		if(i % 3 == 2) {
			triangle.endShape();
			mesh.addChild(triangle);
		}
	}
	
	return mesh;
}
 
Example 7
Source File: TextToPShape.java    From haxademic with MIT License 5 votes vote down vote up
public PShape stringToShape2d(String text, String fontFile) {
	// if letter is in the cache, just send it back
	if(textShape2d.get(text) != null) return textShape2d.get(text);

	// geomerative builds a mesh from text & cached font
	if(fontsCache.get(fontFile) == null) fontsCache.put(fontFile, new RFont(fontFile, 100, RFont.CENTER)); // 
	RFont font = fontsCache.get(fontFile);
	RGroup grp = font.toGroup(text);
	RMesh rMesh = grp.toMesh();
	
	// convert to triangle strips from geomerative strips
	PShape newShape = P.p.createShape(P.GROUP);
	newShape.setName(text);
	for ( int i = 0; i < rMesh.strips.length; i++ ) {
		
		RPoint[] meshPoints = rMesh.strips[i].getPoints();
		PShape triangle = P.p.createShape();
		triangle.beginShape(P.TRIANGLE_STRIP);
		triangle.fill(255);
		triangle.noStroke();
		for ( int ii = 0; ii < meshPoints.length; ii++ ) {
			triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, 0);
		}
		triangle.endShape();
		newShape.addChild(triangle);
	}
	
	// center it
	PShapeUtil.centerShape(newShape);
	
	// cache & return
	textShape2d.put(text, newShape);
	return newShape;
}
 
Example 8
Source File: DwFoldingTile.java    From PixelFlow with MIT License 5 votes vote down vote up
public void displayMesh(PShape pg, DwParticle3D[] particles){
//  pg.beginShape(PConstants.TRIANGLES);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(DEF.style.texture);
  pg.noStroke();
  int          s0,s1,s2;
  int          i0,i1,i2;
  float[]      t0,t1,t2;
  DwParticle3D v0,v1,v2;
  for(int i = 0; i < DEF.FACES_COUNT; i++){
    i0 = faces[i][0];  v0 = particles[i0];  if(v0.all_springs_deactivated) continue;
    i1 = faces[i][1];  v1 = particles[i1];  if(v1.all_springs_deactivated) continue;
    i2 = faces[i][2];  v2 = particles[i2];  if(v2.all_springs_deactivated) continue;
    
    i0 = DEF.FACES[i][0]; s0 = DEF.HILO[i0];  t0 = DEF.TEX_COORDS[i0];
    i1 = DEF.FACES[i][1]; s1 = DEF.HILO[i1];  t1 = DEF.TEX_COORDS[i1];
    i2 = DEF.FACES[i][2]; s2 = DEF.HILO[i2];  t2 = DEF.TEX_COORDS[i2];
    
    int ci = DEF.FACES_COL[i];
    
    if(DEF.style.texture != null){
      DwDisplayUtils.vertex(pg, v0, t0); 
      DwDisplayUtils.vertex(pg, v1, t1); 
      DwDisplayUtils.vertex(pg, v2, t2); 
    } else {
//      pg.fill(DEF.style.COL[s0]); DwDisplayUtils.vertex(pg, v0);
//      pg.fill(DEF.style.COL[s1]); DwDisplayUtils.vertex(pg, v1);
//      pg.fill(DEF.style.COL[s2]); DwDisplayUtils.vertex(pg, v2);

      pg.fill(DEF.style.RGBS[ci][s0]); DwDisplayUtils.vertex(pg, v0);
      pg.fill(DEF.style.RGBS[ci][s1]); DwDisplayUtils.vertex(pg, v1);
      pg.fill(DEF.style.RGBS[ci][s2]); DwDisplayUtils.vertex(pg, v2);
    }
  }
//  pg.endShape();
}
 
Example 9
Source File: DwFoldingTile.java    From PixelFlow with MIT License 5 votes vote down vote up
public void displayMesh(PShape pg, DwIndexedFaceSet ifs){
//  pg.beginShape(PConstants.TRIANGLES);
  pg.textureMode(PConstants.NORMAL);
  pg.texture(DEF.style.texture);
  pg.noStroke();
  int     s0,s1,s2;
  int     i0,i1,i2;
  float[] t0,t1,t2;
  float[] v0,v1,v2;
  for(int i = 0; i < DEF.FACES_COUNT; i++){
    i0 = faces[i][0];  v0 = ifs.verts[i0];
    i1 = faces[i][1];  v1 = ifs.verts[i1];
    i2 = faces[i][2];  v2 = ifs.verts[i2];
    
    i0 = DEF.FACES[i][0]; s0 = DEF.HILO[i0];  t0 = DEF.TEX_COORDS[i0];
    i1 = DEF.FACES[i][1]; s1 = DEF.HILO[i1];  t1 = DEF.TEX_COORDS[i1];
    i2 = DEF.FACES[i][2]; s2 = DEF.HILO[i2];  t2 = DEF.TEX_COORDS[i2];
    
    int ci = DEF.FACES_COL[i];
    
    if(DEF.style.texture != null){
      DwDisplayUtils.vertex(pg, v0, t0); 
      DwDisplayUtils.vertex(pg, v1, t1); 
      DwDisplayUtils.vertex(pg, v2, t2); 
    } else {
//      pg.fill(DEF.style.COL[s0]); DwDisplayUtils.vertex(pg, v0);
//      pg.fill(DEF.style.COL[s1]); DwDisplayUtils.vertex(pg, v1);
//      pg.fill(DEF.style.COL[s2]); DwDisplayUtils.vertex(pg, v2);
      pg.fill(DEF.style.RGBS[ci][s0]); DwDisplayUtils.vertex(pg, v0);
      pg.fill(DEF.style.RGBS[ci][s1]); DwDisplayUtils.vertex(pg, v1);
      pg.fill(DEF.style.RGBS[ci][s2]); DwDisplayUtils.vertex(pg, v2);
    }
  }
//  pg.endShape();
}
 
Example 10
Source File: DwSoftBall2D.java    From PixelFlow with MIT License 5 votes vote down vote up
private PShape createShape(PGraphics pg) {
  PShape shp = pg.createShape();

  shp.beginShape();
  shp.fill(material_color);
  shp.noStroke();
  for(int i = 0; i < num_nodes; i++){
    DwParticle2D pa = particles[i];
    if(pa.all_springs_deactivated) continue;
    shp.vertex(pa.cx, pa.cy);
  }
  shp.endShape();
  return shp;
}
 
Example 11
Source File: DwSoftBall3D.java    From PixelFlow with MIT License 5 votes vote down vote up
private PShape createShape(PGraphics pg){
  int     faces_count = mesh.ifs.getFacesCount();
  int[][] faces       = mesh.ifs.getFaces();
  
  float[] n = new float[3]; // normal buffer
  
  PShape shp = pg.createShape();
  shp.beginShape(PConstants.TRIANGLES);
  shp.noStroke();
  shp.fill(material_color);
  for(int i = 0; i < faces_count; i++){
    int v0 = faces[i][0];
    int v1 = faces[i][1];
    int v2 = faces[i][2];
    DwParticle3D p0 = particles[v0]; if(p0.all_springs_deactivated) continue;
    DwParticle3D p1 = particles[v1]; if(p1.all_springs_deactivated) continue;
    DwParticle3D p2 = particles[v2]; if(p2.all_springs_deactivated) continue;
    
    if(FLAT_SHADING){
      n[0] = n[1] = n[2] = 0;
      DwParticle3D.crossAccum(p0, p1, p2, n);
      shp.normal(n[0], n[1], n[2]); 
      shp.vertex(p0.cx, p0.cy, p0.cz);
      shp.vertex(p1.cx, p1.cy, p1.cz);
      shp.vertex(p2.cx, p2.cy, p2.cz);
    } else {
      n = normals[v0];  shp.normal(n[0], n[1], n[2]);  shp.vertex(p0.cx, p0.cy, p0.cz);
      n = normals[v1];  shp.normal(n[0], n[1], n[2]);  shp.vertex(p1.cx, p1.cy, p1.cz);
      n = normals[v2];  shp.normal(n[0], n[1], n[2]);  shp.vertex(p2.cx, p2.cy, p2.cz);
    }
  }
  shp.endShape();
  return shp;
}
 
Example 12
Source File: Skylight_ClothSimulation.java    From PixelFlow with MIT License 4 votes vote down vote up
public void displayAABB(PGraphics3D canvas, float[] aabb){
  if(shp_aabb == null){
    float xmin = aabb[0], xmax = aabb[3];
    float ymin = aabb[1], ymax = aabb[4];
    float zmin = aabb[2], zmax = aabb[5];
    
    shp_aabb = createShape(GROUP);
    
    PShape plane_zmin = createShape();
    plane_zmin.beginShape(QUAD);
    plane_zmin.stroke(0);
    plane_zmin.strokeWeight(1);
    plane_zmin.fill(16,96,192);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymax, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymax, zmin);
    plane_zmin.endShape(CLOSE);
    shp_aabb.addChild(plane_zmin);
    
    PShape plane_zmax = createShape();
    plane_zmax.beginShape(QUAD);
    plane_zmax.noFill();
    plane_zmax.stroke(0);
    plane_zmax.strokeWeight(1);
    plane_zmax.vertex(xmin, ymin, zmax);
    plane_zmax.vertex(xmax, ymin, zmax);
    plane_zmax.vertex(xmax, ymax, zmax);
    plane_zmax.vertex(xmin, ymax, zmax);
    plane_zmax.endShape(CLOSE);
    shp_aabb.addChild(plane_zmax);
    
    PShape vert_lines = createShape();
    vert_lines.beginShape(LINES);
    vert_lines.stroke(0);
    vert_lines.strokeWeight(1);
    vert_lines.vertex(xmin, ymin, zmin);  vert_lines.vertex(xmin, ymin, zmax);
    vert_lines.vertex(xmax, ymin, zmin);  vert_lines.vertex(xmax, ymin, zmax);
    vert_lines.vertex(xmax, ymax, zmin);  vert_lines.vertex(xmax, ymax, zmax);
    vert_lines.vertex(xmin, ymax, zmin);  vert_lines.vertex(xmin, ymax, zmax);
    vert_lines.endShape();
    shp_aabb.addChild(vert_lines);
    
    PShape corners = createShape();
    corners.beginShape(POINTS);
    corners.stroke(0);
    corners.strokeWeight(7);
    corners.vertex(xmin, ymin, zmin);  corners.vertex(xmin, ymin, zmax);
    corners.vertex(xmax, ymin, zmin);  corners.vertex(xmax, ymin, zmax);
    corners.vertex(xmax, ymax, zmin);  corners.vertex(xmax, ymax, zmax);
    corners.vertex(xmin, ymax, zmin);  corners.vertex(xmin, ymax, zmax);
    corners.endShape();
    shp_aabb.addChild(corners);
  }
  canvas.shape(shp_aabb);
}
 
Example 13
Source File: ParticleSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public PShape createParticleShape(DwParticle2D particle){
  
  final float rad = particle.rad;

  PShape shp_particle = papplet.createShape(PShape.GROUP);
  
  // compute circle resolution, depending on the radius we reduce/increase
  // the number of vertices we need to render
  float threshold1 = 1;   // radius shortening for arc segments
  float threshold2 = 140; // arc between segments
  
  double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad);
  double arc2 = (180 - threshold2) * Math.PI / 180;
  double arc = Math.min(arc1, arc2);
  
  int num_vtx = (int)Math.ceil(2*Math.PI/arc);
  
  // actual circle
  PShape circle = papplet.createShape(PShape.GEOMETRY);
  circle.beginShape();
  circle.noStroke();
  circle.fill(200,100);
  for(int i = 0; i < num_vtx; i++){
    float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * 1;
    float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * 1;
    circle.vertex(vx, vy);
  }
  circle.endShape(PConstants.CLOSE);

  // line, to indicate the velocity-direction of the particle
  PShape line = papplet.createShape(PShape.GEOMETRY);
  line.beginShape(PConstants.LINES);
  line.stroke(255, 100);
  line.strokeWeight(1f/rad);
  line.vertex(0, 0);
  line.vertex(-1, 0);
  line.endShape();
  
  shp_particle.addChild(circle);
  shp_particle.addChild(line);
  
  return shp_particle;
}
 
Example 14
Source File: Softbody3D_Cloth.java    From PixelFlow with MIT License 4 votes vote down vote up
public void displayAABB(float[] aabb){
  if(shp_aabb == null){
    float xmin = aabb[0], xmax = aabb[3];
    float ymin = aabb[1], ymax = aabb[4];
    float zmin = aabb[2], zmax = aabb[5];
    
    shp_aabb = createShape(GROUP);
    
    PShape plane_zmin = createShape();
    plane_zmin.beginShape(QUAD);
    plane_zmin.stroke(0);
    plane_zmin.strokeWeight(1);
    plane_zmin.fill(64);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymax, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymax, zmin);
    plane_zmin.endShape(CLOSE);
    shp_aabb.addChild(plane_zmin);
    
    PShape plane_zmax = createShape();
    plane_zmax.beginShape(QUAD);
    plane_zmax.noFill();
    plane_zmax.stroke(0);
    plane_zmax.strokeWeight(1);
    plane_zmax.vertex(xmin, ymin, zmax);
    plane_zmax.vertex(xmax, ymin, zmax);
    plane_zmax.vertex(xmax, ymax, zmax);
    plane_zmax.vertex(xmin, ymax, zmax);
    plane_zmax.endShape(CLOSE);
    shp_aabb.addChild(plane_zmax);
    
    PShape vert_lines = createShape();
    vert_lines.beginShape(LINES);
    vert_lines.stroke(0);
    vert_lines.strokeWeight(1);
    vert_lines.vertex(xmin, ymin, zmin);  vert_lines.vertex(xmin, ymin, zmax);
    vert_lines.vertex(xmax, ymin, zmin);  vert_lines.vertex(xmax, ymin, zmax);
    vert_lines.vertex(xmax, ymax, zmin);  vert_lines.vertex(xmax, ymax, zmax);
    vert_lines.vertex(xmin, ymax, zmin);  vert_lines.vertex(xmin, ymax, zmax);
    vert_lines.endShape();
    shp_aabb.addChild(vert_lines);
    
    PShape corners = createShape();
    corners.beginShape(POINTS);
    corners.stroke(0);
    corners.strokeWeight(7);
    corners.vertex(xmin, ymin, zmin);  corners.vertex(xmin, ymin, zmax);
    corners.vertex(xmax, ymin, zmin);  corners.vertex(xmax, ymin, zmax);
    corners.vertex(xmax, ymax, zmin);  corners.vertex(xmax, ymax, zmax);
    corners.vertex(xmin, ymax, zmin);  corners.vertex(xmin, ymax, zmax);
    corners.endShape();
    shp_aabb.addChild(corners);
  }
  shape(shp_aabb);
}
 
Example 15
Source File: Softbody3D_Playground.java    From PixelFlow with MIT License 4 votes vote down vote up
public void displayAABB(float[] aabb){
  if(shp_aabb == null){
    float xmin = aabb[0], xmax = aabb[3];
    float ymin = aabb[1], ymax = aabb[4];
    float zmin = aabb[2], zmax = aabb[5];
    
    shp_aabb = createShape(GROUP);
    
    PShape plane_zmin = createShape();
    plane_zmin.beginShape(QUAD);
    plane_zmin.stroke(0);
    plane_zmin.strokeWeight(1);
    plane_zmin.fill(192);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymax, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymax, zmin);
    plane_zmin.endShape(CLOSE);
    shp_aabb.addChild(plane_zmin);
    
    PShape plane_zmax = createShape();
    plane_zmax.beginShape(QUAD);
    plane_zmax.noFill();
    plane_zmax.stroke(0);
    plane_zmax.strokeWeight(1);
    plane_zmax.vertex(xmin, ymin, zmax);
    plane_zmax.vertex(xmax, ymin, zmax);
    plane_zmax.vertex(xmax, ymax, zmax);
    plane_zmax.vertex(xmin, ymax, zmax);
    plane_zmax.endShape(CLOSE);
    shp_aabb.addChild(plane_zmax);
    
    PShape vert_lines = createShape();
    vert_lines.beginShape(LINES);
    vert_lines.stroke(0);
    vert_lines.strokeWeight(1);
    vert_lines.vertex(xmin, ymin, zmin);  vert_lines.vertex(xmin, ymin, zmax);
    vert_lines.vertex(xmax, ymin, zmin);  vert_lines.vertex(xmax, ymin, zmax);
    vert_lines.vertex(xmax, ymax, zmin);  vert_lines.vertex(xmax, ymax, zmax);
    vert_lines.vertex(xmin, ymax, zmin);  vert_lines.vertex(xmin, ymax, zmax);
    vert_lines.endShape();
    shp_aabb.addChild(vert_lines);
    
    PShape corners = createShape();
    corners.beginShape(POINTS);
    corners.stroke(0);
    corners.strokeWeight(7);
    corners.vertex(xmin, ymin, zmin);  corners.vertex(xmin, ymin, zmax);
    corners.vertex(xmax, ymin, zmin);  corners.vertex(xmax, ymin, zmax);
    corners.vertex(xmax, ymax, zmin);  corners.vertex(xmax, ymax, zmax);
    corners.vertex(xmin, ymax, zmin);  corners.vertex(xmin, ymax, zmax);
    corners.endShape();
    shp_aabb.addChild(corners);
  }
  shape(shp_aabb);
}
 
Example 16
Source File: Softbody3D_ParticleCollisionSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public void displayAABB(float[] aabb){
  if(shp_aabb == null){
    float xmin = aabb[0], xmax = aabb[3];
    float ymin = aabb[1], ymax = aabb[4];
    float zmin = aabb[2], zmax = aabb[5];
    
    shp_aabb = createShape(GROUP);
    
    PShape plane_zmin = createShape();
    plane_zmin.beginShape(QUAD);
    plane_zmin.stroke(0);
    plane_zmin.strokeWeight(1);
    plane_zmin.fill(192);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymax, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymax, zmin);
    plane_zmin.endShape(CLOSE);
    shp_aabb.addChild(plane_zmin);
    
    PShape plane_zmax = createShape();
    plane_zmax.beginShape(QUAD);
    plane_zmax.noFill();
    plane_zmax.stroke(0);
    plane_zmax.strokeWeight(1);
    plane_zmax.vertex(xmin, ymin, zmax);
    plane_zmax.vertex(xmax, ymin, zmax);
    plane_zmax.vertex(xmax, ymax, zmax);
    plane_zmax.vertex(xmin, ymax, zmax);
    plane_zmax.endShape(CLOSE);
    shp_aabb.addChild(plane_zmax);
    
    PShape vert_lines = createShape();
    vert_lines.beginShape(LINES);
    vert_lines.stroke(0);
    vert_lines.strokeWeight(1);
    vert_lines.vertex(xmin, ymin, zmin);  vert_lines.vertex(xmin, ymin, zmax);
    vert_lines.vertex(xmax, ymin, zmin);  vert_lines.vertex(xmax, ymin, zmax);
    vert_lines.vertex(xmax, ymax, zmin);  vert_lines.vertex(xmax, ymax, zmax);
    vert_lines.vertex(xmin, ymax, zmin);  vert_lines.vertex(xmin, ymax, zmax);
    vert_lines.endShape();
    shp_aabb.addChild(vert_lines);
    
    PShape corners = createShape();
    corners.beginShape(POINTS);
    corners.stroke(0);
    corners.strokeWeight(7);
    corners.vertex(xmin, ymin, zmin);  corners.vertex(xmin, ymin, zmax);
    corners.vertex(xmax, ymin, zmin);  corners.vertex(xmax, ymin, zmax);
    corners.vertex(xmax, ymax, zmin);  corners.vertex(xmax, ymax, zmax);
    corners.vertex(xmin, ymax, zmin);  corners.vertex(xmin, ymax, zmax);
    corners.endShape();
    shp_aabb.addChild(corners);
  }
  shape(shp_aabb);
}
 
Example 17
Source File: TextToPShape.java    From haxademic with MIT License 4 votes vote down vote up
public PShape stringToShape3d(String text, float depth, String fontFile) {
	// if letter is in the cache, just send it back
	if(textShape3d.get(text) != null) return textShape3d.get(text);

	// geomerative builds a mesh from text & cached font
	if(fontsCache.get(fontFile) == null) fontsCache.put(fontFile, new RFont(fontFile, 100, RFont.CENTER)); // 
	RFont font = fontsCache.get(fontFile);
	RGroup grp = font.toGroup(text);
	RMesh rMesh = grp.toMesh();
	
	// 3d measurements
	float halfDepth = depth / 2f;
	
	// convert to triangle strips from geomerative strips
	PShape newShape = P.p.createShape(P.GROUP);
	newShape.setName(text);
	for ( int i = 0; i < rMesh.strips.length; i++ ) {
		RPoint[] meshPoints = rMesh.strips[i].getPoints();
		PShape triangle = P.p.createShape();
		
		// back
		triangle.beginShape(P.TRIANGLE_STRIP);
		triangle.fill(255);
		triangle.noStroke();
		for ( int ii = 0; ii < meshPoints.length; ii++ ) {
			triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, -halfDepth);
		}
		triangle.endShape();
		newShape.addChild(triangle);

		// front
		triangle = P.p.createShape();
		triangle.beginShape(P.TRIANGLE_STRIP);
		triangle.fill(255);
		triangle.noStroke();
		for ( int ii = 0; ii < meshPoints.length; ii++ ) {
			triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, halfDepth);
		}
		triangle.endShape();
		newShape.addChild(triangle);
		
		// wall (drawing quads across strip points, which is weird)
		triangle = P.p.createShape();
		triangle.beginShape(P.QUADS);
		triangle.fill(255);
		triangle.noStroke();
		for ( int ii = 0; ii < meshPoints.length - 2; ii++ ) {
			triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, -halfDepth);
			triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, halfDepth);
			triangle.vertex(meshPoints[ii+1].x, meshPoints[ii+1].y, halfDepth);
			triangle.vertex(meshPoints[ii+1].x, meshPoints[ii+1].y, -halfDepth);

			triangle.vertex(meshPoints[ii+2].x, meshPoints[ii+2].y, -halfDepth);
			triangle.vertex(meshPoints[ii+2].x, meshPoints[ii+2].y, halfDepth);
			triangle.vertex(meshPoints[ii+1].x, meshPoints[ii+1].y, halfDepth);
			triangle.vertex(meshPoints[ii+1].x, meshPoints[ii+1].y, -halfDepth);
			
			triangle.vertex(meshPoints[ii+2].x, meshPoints[ii+2].y, -halfDepth);
			triangle.vertex(meshPoints[ii+2].x, meshPoints[ii+2].y, halfDepth);
			triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, halfDepth);
			triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, -halfDepth);
		}
		triangle.endShape();
		newShape.addChild(triangle);
	}
	
	// center it
	PShapeUtil.centerShape(newShape);
	
	// cache & return
	textShape3d.put(text, newShape);
	return newShape;
}
 
Example 18
Source File: ParticleSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public PShape createParticleShape(DwParticle2D particle, PImage sprite_img){
    
    final float rad = particle.rad;

    PShape shp_particle = papplet.createShape(PShape.GROUP);
    
    if( PARTICLE_SHAPE_IDX >= 0 && PARTICLE_SHAPE_IDX < 4){
      
      PShape sprite = papplet.createShape(PShape.GEOMETRY);
      sprite.beginShape(PConstants.QUAD);
      sprite.noStroke();
      sprite.noFill();
      sprite.textureMode(PConstants.NORMAL);
      sprite.texture(sprite_img);
      sprite.normal(0, 0, 1);
      sprite.vertex(-rad, -rad, 0, 0);
      sprite.vertex(+rad, -rad, 1, 0);
      sprite.vertex(+rad, +rad, 1, 1);
      sprite.vertex(-rad, +rad, 0, 1);
      sprite.endShape();
      
      shp_particle.addChild(sprite);
    }
    else if( PARTICLE_SHAPE_IDX == 4){   
      
      float threshold1 = 1;   // radius shortening for arc segments
      float threshold2 = 140; // arc between segments
      
      double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad);
      double arc2 = (180 - threshold2) * Math.PI / 180;
      double arc = Math.min(arc1, arc2);
      
      int num_vtx = (int)Math.ceil(2*Math.PI/arc);
      
//      System.out.println(num_vtx);

      PShape circle = papplet.createShape(PShape.GEOMETRY);
      circle.beginShape();
      circle.noStroke();
      circle.fill(200,100);
      for(int i = 0; i < num_vtx; i++){
        float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * rad;
        float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * rad;
        circle.vertex(vx, vy);
      }
      circle.endShape(PConstants.CLOSE);

      PShape line = papplet.createShape(PShape.GEOMETRY);
      line.beginShape(PConstants.LINES);
      line.stroke(0, 100);
      line.strokeWeight(1);
      line.vertex(0, 0);
      line.vertex(-(rad-1), 0);
      line.endShape();
      
//      PShape circle = papplet.createShape(PConstants.ELLIPSE, 0, 0, rad*2, rad*2);
//      circle.setStroke(false);
//      circle.setFill(papplet.color(200,100));
//
//      PShape line = papplet.createShape(PConstants.LINE, 0, 0, -(rad-1), 0);
//      line.setStroke(papplet.color(0,200));
//      line.setStrokeWeight(1); 
      
      shp_particle.addChild(circle);
      shp_particle.addChild(line);
    }
    
    return shp_particle;
    
  }
 
Example 19
Source File: PShapeUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static PShape shapeFromImage(PImage img) {
		img.loadPixels();
		PShape newShape = P.p.createShape(P.GROUP);
		newShape.setStroke(false);
		
		for( int x=0; x < img.width; x++ ){
			for(int y=0; y < img.height; y++){
				int pixelColor = ImageUtil.getPixelColor( img, x, y );
//				float pixelBrightness = P.p.brightness( pixelColor );
				if(pixelColor != ImageUtil.TRANSPARENT_PNG) {
//				if( pixelColor != ImageUtil.EMPTY_WHITE_INT && pixelColor != ImageUtil.WHITE_INT ) {
					P.p.fill(EasingColor.redFromColorInt(pixelColor), EasingColor.greenFromColorInt(pixelColor), EasingColor.blueFromColorInt(pixelColor), 255);
					P.p.noStroke();
					
					PShape sh = P.p.createShape();
					sh.beginShape(P.TRIANGLES);
					sh.fill( EasingColor.redFromColorInt(pixelColor), EasingColor.greenFromColorInt(pixelColor), EasingColor.blueFromColorInt(pixelColor), 255 );
					
					// BL, BR, TR, TL
					float size = 0.5f;

					// front
					sh.vertex(x - size, y + size,  size);
					sh.vertex(x + size, y + size,  size);
					sh.vertex(x + size, y - size,  size);
					
					sh.vertex(x - size, y + size,  size);
					sh.vertex(x + size, y - size,  size);
					sh.vertex(x - size, y - size,  size);

					// back
					sh.vertex(x - size, y + size,  -size);
					sh.vertex(x + size, y + size,  -size);
					sh.vertex(x + size, y - size,  -size);
					
					sh.vertex(x - size, y + size,  -size);
					sh.vertex(x + size, y - size,  -size);
					sh.vertex(x - size, y - size,  -size);

					// left
					sh.vertex(x - size, y + size, -size);
					sh.vertex(x - size, y + size,  size);
					sh.vertex(x - size, y - size,  size);

					sh.vertex(x - size, y + size, -size);
					sh.vertex(x - size, y - size,  size);
					sh.vertex(x - size, y - size, -size);

					// right
					sh.vertex(x + size, y + size, -size);
					sh.vertex(x + size, y + size,  size);
					sh.vertex(x + size, y - size,  size);

					sh.vertex(x + size, y + size, -size);
					sh.vertex(x + size, y - size,  size);
					sh.vertex(x + size, y - size, -size);
					
					// floor
					sh.vertex(x - size, y + size, -size);
					sh.vertex(x + size, y + size, -size);
					sh.vertex(x + size, y + size,  size);

					sh.vertex(x + size, y + size,  size);
					sh.vertex(x - size, y + size,  size);
					sh.vertex(x - size, y + size, -size);

					// ceiling
					sh.vertex(x - size, y - size, -size);
					sh.vertex(x + size, y - size, -size);
					sh.vertex(x + size, y - size,  size);

					sh.vertex(x + size, y - size,  size);
					sh.vertex(x - size, y - size,  size);
					sh.vertex(x - size, y - size, -size);

					sh.endShape();

					newShape.addChild(sh);
				}
			}
		}
		
		return newShape;
	}
 
Example 20
Source File: ParticleSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public PShape createParticleShape(DwParticle2D particle, PImage sprite_img){
    
    final float rad = particle.rad;

    PShape shp_particle = papplet.createShape(PShape.GROUP);
    
    if( PARTICLE_SHAPE_IDX >= 0 && PARTICLE_SHAPE_IDX < 4){
      
      PShape sprite = papplet.createShape(PShape.GEOMETRY);
      sprite.beginShape(PConstants.QUAD);
      sprite.noStroke();
      sprite.noFill();
      sprite.textureMode(PConstants.NORMAL);
      sprite.texture(sprite_img);
      sprite.normal(0, 0, 1);
      sprite.vertex(-rad, -rad, 0, 0);
      sprite.vertex(+rad, -rad, 1, 0);
      sprite.vertex(+rad, +rad, 1, 1);
      sprite.vertex(-rad, +rad, 0, 1);
      sprite.endShape();
      
      shp_particle.addChild(sprite);
    }
    else if( PARTICLE_SHAPE_IDX == 4){   
      
      float threshold1 = 1;   // radius shortening for arc segments
      float threshold2 = 140; // arc between segments
      
      double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad);
      double arc2 = (180 - threshold2) * Math.PI / 180;
      double arc = Math.min(arc1, arc2);
      
      int num_vtx = (int)Math.ceil(2*Math.PI/arc);
      
//      System.out.println(num_vtx);

      PShape circle = papplet.createShape(PShape.GEOMETRY);
      circle.beginShape();
      circle.noStroke();
      circle.fill(200,100);
      for(int i = 0; i < num_vtx; i++){
        float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * rad;
        float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * rad;
        circle.vertex(vx, vy);
      }
      circle.endShape(PConstants.CLOSE);

      PShape line = papplet.createShape(PShape.GEOMETRY);
      line.beginShape(PConstants.LINES);
      line.stroke(0, 100);
      line.strokeWeight(1);
      line.vertex(0, 0);
      line.vertex(-(rad-1), 0);
      line.endShape();
      
//      PShape circle = papplet.createShape(PConstants.ELLIPSE, 0, 0, rad*2, rad*2);
//      circle.setStroke(false);
//      circle.setFill(papplet.color(200,100));
//
//      PShape line = papplet.createShape(PConstants.LINE, 0, 0, -(rad-1), 0);
//      line.setStroke(papplet.color(0,200));
//      line.setStrokeWeight(1); 
      
      shp_particle.addChild(circle);
      shp_particle.addChild(line);
    }
    
    return shp_particle;
    
  }