Java Code Examples for processing.core.PGraphics#createShape()

The following examples show how to use processing.core.PGraphics#createShape() . 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 PShape createShape(PGraphics pg){
  PShape shp = pg.createShape(PConstants.GROUP);

  PShape[] shp_grid = new PShape[6];
  for(int i = 0; i < shp_grid.length; i++){
    shp_grid[i] = pg.createShape();
    shp.addChild(shp_grid[i]);
  }
  
  shp_grid[0].setName("gridXYp");
  shp_grid[1].setName("gridXYn");
  shp_grid[2].setName("gridYZp");
  shp_grid[3].setName("gridYZn");
  shp_grid[4].setName("gridXZp");
  shp_grid[5].setName("gridXZn");

                  displayGridXY(shp_grid[0], normals[0], 0        , texture_XYp);
  if(nodes_z > 1) displayGridXY(shp_grid[1], normals[1], nodes_z-1, texture_XYn);
                  displayGridYZ(shp_grid[2], normals[2], 0        , texture_YZp);
  if(nodes_x > 1) displayGridYZ(shp_grid[3], normals[3], nodes_x-1, texture_YZn);
                  displayGridXZ(shp_grid[4], normals[4], 0        , texture_XZp);
  if(nodes_y > 1) displayGridXZ(shp_grid[5], normals[5], nodes_y-1, texture_XZn);
  return shp;
}
 
Example 2
Source File: Icosahedron.java    From haxademic with MIT License 6 votes vote down vote up
public static PShape createIcosahedron(PGraphics pg, int level, PImage img) {
	// the icosahedron is created with positions, normals and texture coordinates in the above class
	Icosahedron ico = new Icosahedron(level);
	pg.textureMode(P.NORMAL); // set textureMode to normalized (range 0 to 1);
	PShape mesh = pg.createShape(); // create the initial PShape
	mesh.beginShape(P.TRIANGLES); // define the PShape type: TRIANGLES
	mesh.noStroke();
	if(img != null) mesh.texture(img);

	// put all the vertices, uv texture coordinates and normals into the PShape
	for (int i=0; i<ico.positions.size(); i++) {
		PVector pos = ico.positions.get(i);
		PVector t = ico.texCoords.get(i);
		PVector n = ico.normals.get(i);
		mesh.normal(n.x, n.y, n.z);
		mesh.vertex(pos.x, pos.y, pos.z, t.x, t.y);
	}
	mesh.endShape();
	return mesh;
}
 
Example 3
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 4
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 5
Source File: DwSoftGrid2D.java    From PixelFlow with MIT License 5 votes vote down vote up
@Override
public void createShapeMesh(PGraphics pg) {
  PShape shp = pg.createShape();
  shp.setName("gridXYp");
  displayGridXY(shp, texture_XYp);
  setShapeMesh(pg.parent, shp);
}
 
Example 6
Source File: DwSoftGrid2D.java    From PixelFlow with MIT License 5 votes vote down vote up
@Override
public void createShapeWireframe(PGraphics pg, DwStrokeStyle style){
  PShape shp = pg.createShape();
  displayGridXY(shp, texture_XYp);
  shp.setTexture(null);
  shp.setFill(false);
  shp.setStroke(true);
  shp.setStroke(style.stroke_color);
  shp.setStrokeWeight(style.stroke_weight);
  
  setShapeWireframe(pg.parent, shp);
}
 
Example 7
Source File: DwFoldingSoftBody.java    From PixelFlow with MIT License 5 votes vote down vote up
private PShape createShape(PGraphics pg){
  PShape shp = pg.createShape();
  shp.beginShape(PConstants.TRIANGLES);
  foldingmodel.display(shp, this);
  shp.endShape();
  return shp;
}