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

The following examples show how to use processing.core.PShape#beginShape() . 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: AntiAliasingComparison.java    From PixelFlow with MIT License 6 votes vote down vote up
public PShape createGridXY(int lines, float s){
  PShape shp_gridxy = createShape();
  shp_gridxy.beginShape(LINES);
  shp_gridxy.stroke(0);
  shp_gridxy.strokeWeight(1f);
  float d = lines*s;
  for(int i = 0; i <= lines; i++){
    shp_gridxy.vertex(-d,-i*s,0); shp_gridxy.vertex(d,-i*s,0);
    shp_gridxy.vertex(-d,+i*s,0); shp_gridxy.vertex(d,+i*s,0);
    
    shp_gridxy.vertex(-i*s,-d,0); shp_gridxy.vertex(-i*s,d,0);
    shp_gridxy.vertex(+i*s,-d,0); shp_gridxy.vertex(+i*s,d,0);
  }
  shp_gridxy.endShape();
  return shp_gridxy;
}
 
Example 2
Source File: ShaderVertexTrigDeform.java    From haxademic with MIT License 6 votes vote down vote up
PShape createCylinder(float r, float h, int detail, PImage tex) {
	textureMode(NORMAL);
	PShape sh = createShape();
	sh.beginShape(QUAD_STRIP);
	sh.noStroke();
	sh.texture(tex);
	for (int i = 0; i <= detail; i++) {
		float angle = TWO_PI / detail;
		float x = sin(i * angle);
		float z = cos(i * angle);
		float u = (float)i / detail;
		sh.normal(x, 0, z);
		sh.vertex(x * r, -h/2, z * r, u, 0);
		sh.vertex(x * r, +h/2, z * r, u, 1);    
	}
	sh.endShape(); 
	return sh;
}
 
Example 3
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 4
Source File: Shapes.java    From haxademic with MIT License 6 votes vote down vote up
public static PShape createStrip(float width, float height, int detail) {
	P.p.textureMode(P.NORMAL); 
	PShape sh = P.p.createShape();
	sh.beginShape(P.QUAD_STRIP);
	sh.noStroke();
	float xStart = -width / 2f;
	float yStart = -height / 2f;
	float xSegment = width / (float) detail;
	for (int i = 0; i <= detail; i++) {
		float x = xStart + i * xSegment;
		float u = (float)i / (float)detail; // x progress
		sh.vertex(x, yStart, 		  0, u, 0);
		sh.vertex(x, yStart + height, 0, u, 1);
	}
	sh.endShape();
	P.p.textureMode(P.IMAGE); 	// reset 
	return sh;
}
 
Example 5
Source File: Shapes.java    From haxademic with MIT License 6 votes vote down vote up
public static PShape createSheetPoints(int detail, float width, float height) {
	PShape sh = P.p.createShape();
	sh.beginShape(PConstants.POINTS);
	sh.stroke(255);
	sh.strokeWeight(1);
	sh.noFill();
	float cellW = width / detail;
	float cellH = height / detail;
	// int numVertices = 0;
	for (int col = 0; col < detail; col++) {
		for (int row = 0; row < detail; row++) {
			float xU = col * cellW;
			float yV = row * cellH;
			float x = -width/2f + col * cellW;
			float y = -height/2f + row * cellH;
			float z = 0;
			sh.normal(x, y, z);
			sh.vertex(x, y, z, P.map(xU, 0, width, 0, 1), P.map(yV, 0, height, 0, 1));
			// numVertices += 1;
		}
	}
	// P.println("createSheet() vertices:", numVertices);
	sh.endShape(); 
	return sh;
}
 
Example 6
Source File: TextureEQLinesTerrain.java    From haxademic with MIT License 5 votes vote down vote up
public TextureEQLinesTerrain( int width, int height ) {
	super(width, height);
	
	// build scrolling audio map history
	eqHistory = PG.newPG(256, 256, false, false);
	eqHistory.noSmooth();
	OpenGLUtil.setTextureQualityLow(eqHistory);
	eqHistoryCopy = PG.newPG(256, 256);
	eqHistoryCopy.noSmooth();
	OpenGLUtil.setTextureQualityLow(eqHistoryCopy);

	// build sheet mesh
	shape = P.p.createShape(P.GROUP);
	int rows = eqHistory.height;
	int cols = eqHistory.width;
	for (int y = 0; y < rows; y++) {
		PShape line = P.p.createShape();
		line.beginShape();
		line.stroke(255);
		line.strokeWeight(1);
		line.noFill();
		for (int x = 0; x < cols; x++) {
			line.vertex(x * 20f, y * 20f, 0);
		}
		line.endShape();
		shape.addChild(line);
	}

	// normalize & texture mesh
	PShapeUtil.centerShape(shape);
	PShapeUtil.scaleShapeToHeight(shape, height * 1f);
	PShapeUtil.addTextureUVToShape(shape, eqHistory);
	shapeExtent = PShapeUtil.getMaxExtent(shape);
	shape.disableStyle();
	shape.setTexture(eqHistory);
}
 
Example 7
Source File: PShapeUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape meshShapeToPointsShape(PShape origShape) {
	PShape newShape = P.p.createShape();
	newShape.beginShape(PConstants.POINTS);
	newShape.stroke(255);
	newShape.strokeWeight(1);
	newShape.noFill();
	addVerticesToPointShape(origShape, newShape);
	newShape.endShape();
	return newShape;
}
 
Example 8
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 9
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 10
Source File: Demo_LinesDeformAndTextureFilter.java    From haxademic with MIT License 5 votes vote down vote up
protected void firstFrame() {
	// load texture
	perlin = new PerlinTexture(p, 256, 256);
	texture = perlin.texture();
	DebugView.setTexture("texture", texture);
	
	// build sheet mesh
	shape = p.createShape(P.GROUP);
	int rows = 200;
	int cols = 500;
	for (int y = 0; y < rows; y++) {
		PShape line = P.p.createShape();
		line.beginShape();
		line.stroke(255);
		line.strokeWeight(1);
		line.noFill();
		for (int x = 0; x < cols; x++) {
			line.vertex(x * 10f, y * 10f, 0);
		}
		line.endShape();
		shape.addChild(line);
	}
	PShapeUtil.centerShape(shape);
	PShapeUtil.scaleShapeToHeight(shape, p.height * 2f);
	PShapeUtil.addTextureUVToShape(shape, texture);
	shapeExtent = PShapeUtil.getMaxExtent(shape);
	shape.disableStyle();

	shape.setTexture(texture);
	DebugView.setValue("shape.getVertexCount();", PShapeUtil.vertexCount(shape));
}
 
Example 11
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape createSheet(int cols, int rows, PImage tex) {
	P.p.textureMode(P.NORMAL); 
	// P.println("Shapes.createSheet() setting textureMode is weird to do here... Maybe should be PAppletHax default?");
	PShape sh = P.p.createShape();
	sh.beginShape(P.QUADS);
	sh.noStroke();
	sh.texture(tex);
	float cellW = (float) tex.width / (float) cols;
	float cellH = (float) tex.height / (float) rows;
	// int numVertices = 0;
	for (int col = 0; col < cols; col++) {
		for (int row = 0; row < rows; row++) {
			float xU = col * cellW;
			float yV = row * cellH;
			float x = -tex.width/2f + col * cellW;
			float y = -tex.height/2f + row * cellH;
			float z = 0;
			sh.normal(x, y, z);
			sh.vertex(x, y, z, 					P.map(xU, 0, tex.width, 0, 1), 			P.map(yV, 0, tex.height, 0, 1));
			sh.vertex(x, y + cellH, z, 			P.map(xU, 0, tex.width, 0, 1), 			P.map(yV + cellH, 0, tex.height, 0, 1));    
			sh.vertex(x + cellW, y + cellH, z, 	P.map(xU + cellW, 0, tex.width, 0, 1), 	P.map(yV + cellH, 0, tex.height, 0, 1));    
			sh.vertex(x + cellW, y, z, 			P.map(xU + cellW, 0, tex.width, 0, 1), 	P.map(yV, 0, tex.height, 0, 1));
			// numVertices++;
		}
	}
	// P.println("createSheet() vertices:", numVertices);
	sh.endShape(); 
	P.p.textureMode(P.IMAGE); 	// reset 
	return sh;
}
 
Example 12
Source File: Demo_PShapeUtil_exportMesh.java    From haxademic with MIT License 5 votes vote down vote up
protected void firstFrame() {


	p.sphereDetail(10);
	float extent = p.width/5f;
	shapeIcos = Icosahedron.createIcosahedron(p.g, 4, img);
	PShapeUtil.scaleShapeToExtent(shapeIcos, extent);
	
	
	PShape newIcos = p.createShape();
	newIcos.beginShape(PConstants.TRIANGLES);
	PVector v = new PVector();
	for (int i = 0; i < shapeIcos.getVertexCount(); i+=3) {
		// get current vertex
		shapeIcos.getVertex(i, v);
		v.mult(4f); // scale up for noise since scaleSvgToExtent doesn't change the actual vertices
		float noiseExclude = p.noise(v.x, v.y, v.z);
		// selectively add faces depending on noise
		if(noiseExclude > 0.45f) {
			shapeIcos.getVertex(i, v);
			v.mult(extent * (1f + p.noise(v.x, v.y, v.z)));
			newIcos.vertex(v.x, v.y, v.z);
			shapeIcos.getVertex(i+1, v);
			v.mult(extent * (1f + p.noise(v.x, v.y, v.z)));
			newIcos.vertex(v.x, v.y, v.z);
			shapeIcos.getVertex(i+2, v);
			v.mult(extent * (1f + p.noise(v.x, v.y, v.z)));
			newIcos.vertex(v.x, v.y, v.z);
		}
	}
	newIcos.endShape();
	shapeIcos = newIcos;
}
 
Example 13
Source File: KinectShaderVertexDeform.java    From haxademic with MIT License 5 votes vote down vote up
PShape createSheet(int detail, PImage tex) {
	p.textureMode(NORMAL);
	PShape sh = p.createShape();
	sh.beginShape(QUADS);
	sh.noStroke();
	sh.noFill();
	sh.texture(tex);
	float cellW = tex.width / detail;
	float cellH = tex.height / detail;
	int numVertices = 0;
	for (int col = 0; col < tex.width; col += cellW) {
		for (int row = 0; row < tex.height; row += cellH) {
			float xU = col;
			float yV = row;
			float x = -tex.width/2f + xU;
			float y = -tex.height/2f + yV;
			float z = 0;
			sh.normal(x, y, z);
			sh.vertex(x, y, z, 					P.map(xU, 0, tex.width, 0, 1f), P.map(yV, 0, tex.height, 0, 1f));
			sh.vertex(x, y + cellH, z, 			P.map(xU, 0, tex.width, 0, 1f), P.map(yV + cellH, 0, tex.height, 0, 1f));    
			sh.vertex(x + cellW, y + cellH, z,	P.map(xU + cellW, 0, tex.width, 0, 1f), P.map(yV + cellH, 0, tex.height, 0, 1f));    
			sh.vertex(x + cellW, y, z, 			P.map(xU + cellW, 0, tex.width, 0, 1f), P.map(yV, 0, tex.height, 0, 1f));
			numVertices++;
		}
	}
	P.println(numVertices, "vertices");
	sh.endShape(); 
	return sh;
}
 
Example 14
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 15
Source File: Shapes.java    From haxademic with MIT License 4 votes vote down vote up
public static PShape createDisc(float radius, int vertices, int rows, PImage tex) {
	P.p.textureMode(P.NORMAL); 
	PShape sh = P.p.createShape();
	sh.beginShape(P.TRIANGLES);
	sh.textureMode(P.NORMAL);
	if(tex != null) sh.texture(tex);
	sh.noStroke();
	
	float radiusTwo = radius * 2f;
	float rowSize = radius / (float) rows;
	float segmentRads = P.TWO_PI / vertices;
	for( int v = 0; v < vertices; v++ ) {
		for( int r = 0; r < rows; r++ ) {
			float curRads = v * segmentRads;
			float nextRads = (v+1) * segmentRads;
			float curRadius = r * rowSize; 
			float nextRadius = (r+1) * rowSize; 
			
			float x1 = P.cos(curRads) * curRadius;
			float y1 = P.sin(curRads) * curRadius;
			float u1 = (x1 + radius) / radiusTwo;	// normalize within texture - move from being centered
			float v1 = (y1 + radius) / radiusTwo;
			
			float x2 = P.cos(curRads) * nextRadius;
			float y2 = P.sin(curRads) * nextRadius;
			float u2 = (x2 + radius) / radiusTwo;	// normalize within texture - move from being centered
			float v2 = (y2 + radius) / radiusTwo;

			float x3 = P.cos(nextRads) * nextRadius;
			float y3 = P.sin(nextRads) * nextRadius;
			float u3 = (x3 + radius) / radiusTwo;	// normalize within texture - move from being centered
			float v3 = (y3 + radius) / radiusTwo;

			float x4 = P.cos(nextRads) * curRadius;
			float y4 = P.sin(nextRads) * curRadius;
			float u4 = (x4 + radius) / radiusTwo;	// normalize within texture - move from being centered
			float v4 = (y4 + radius) / radiusTwo;
			
			sh.vertex( x1, y1, 0, u1, v1 );
			sh.vertex( x2, y2, 0, u2, v2 );
			sh.vertex( x3, y3, 0, u3, v3 );
			
			sh.vertex( x1, y1, 0, u1, v1 );
			sh.vertex( x4, y4, 0, u4, v4 );
			sh.vertex( x3, y3, 0, u3, v3 );
		}
	}

	sh.endShape();
	return sh;
}
 
Example 16
Source File: Skylight_BulletPhysics_CellFracture.java    From PixelFlow with MIT License 4 votes vote down vote up
public PShape createVoronoiCellShape(WB_VoronoiCell3D cell, Vector3f center_of_mass){
    
 
    boolean[] on_bounds = cell.getVerticesOnBoundary();
    
    PShape voronoi_cell = createShape(GROUP);
    
    WB_Mesh mesh = cell.getMesh();
    int[][] faces = mesh.getFacesAsInt();

    int on_boundary = 0;
    for(int j = 0; j < faces.length; j++){
      int[] face = faces[j];
      WB_Vector normal = mesh.getFaceNormal(j);
      
      PShape polygon = createShape();

      polygon.beginShape(POLYGON);
      polygon.normal(normal.xf(), normal.yf(), normal.zf());
      
      for(int k = 0; k < face.length; k++){
        WB_Coord vtx = mesh.getVertex(face[k]);
        
        float x = vtx.xf() - center_of_mass.x;
        float y = vtx.yf() - center_of_mass.y;
        float z = vtx.zf() - center_of_mass.z;
        polygon.vertex(x,y,z);
        
        if(on_bounds[face[k]]){
          on_boundary++;
        }
      }
      
      polygon.endShape(CLOSE);
//      polygon.setFill(true);
//      if(on_boundary == face.length){
//      if(on_boundary > 0){
//        polygon.setFill(color(8));
//      } else {
//        polygon.setFill(color(255,0,0));
//      }
//    
//      polygon.setStroke(false);
      
      
      voronoi_cell.addChild(polygon);
    }

    String wire = "";
    voronoi_cell.setFill(true);
//    if(on_boundary == face.length){
    if(on_boundary > 0){
      voronoi_cell.setFill(color(32));
      wire = "[wire]";
    } else {
      voronoi_cell.setFill(color(255,8,0));
    }
  
    voronoi_cell.setStroke(false);
    voronoi_cell.setStroke(color(64,4,0));
    voronoi_cell.setName("[cvh] "+wire);

    return voronoi_cell;
  }
 
Example 17
Source File: PShapeUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static PShape createExtrudedShape(PShape shape, float depth, PShape newShape) {
	if(newShape == null) newShape = P.p.createShape();

	newShape.beginShape(P.TRIANGLES);
	// top
	for (int i = 0; i < shape.getVertexCount() - 3; i+=3) {
		// copy triangle vertices & UV coords
		PVector v1 = shape.getVertex(i);
		PVector v2 = shape.getVertex(i+1);
		PVector v3 = shape.getVertex(i+2);
		float texU1 = shape.getTextureU(i);
		float texV1 = shape.getTextureU(i);
		float texU2 = shape.getTextureU(i+1);
		float texV2 = shape.getTextureU(i+1);
		float texU3 = shape.getTextureU(i+2);
		float texV3 = shape.getTextureU(i+2);
		
		// half depth to keep new model centered on z-axis
		float halfDepth = depth / 2f;
		
		// top
		newShape.vertex(v1.x, v1.y, halfDepth, texU1, texV1);
		newShape.vertex(v2.x, v2.y, halfDepth, texU2, texV2);
		newShape.vertex(v3.x, v3.y, halfDepth, texU3, texV3);
		
		// bottom
		newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1);
		newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2);
		newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3);
		
		// walls
		// wall 1
		newShape.vertex(v1.x, v1.y,  halfDepth, texU1, texV1);
		newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1);
		newShape.vertex(v2.x, v2.y,  halfDepth, texU2, texV2);

		newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1);
		newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2);
		newShape.vertex(v2.x, v2.y,  halfDepth, texU2, texV2);

		// wall 2
		newShape.vertex(v2.x, v2.y,  halfDepth, texU2, texV2);
		newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2);
		newShape.vertex(v3.x, v3.y,  halfDepth, texU3, texV3);
		
		newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2);
		newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3);
		newShape.vertex(v3.x, v3.y,  halfDepth, texU3, texV3);
		
		// wall 3
		newShape.vertex(v3.x, v3.y,  halfDepth, texU3, texV3);
		newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3);
		newShape.vertex(v1.x, v1.y,  halfDepth, texU1, texV1);
		
		newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3);
		newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1);
		newShape.vertex(v1.x, v1.y,  halfDepth, texU1, texV1);
	}
	
	newShape.endShape();
	
	// recurse through original shape children if nested shapes
	for (int j = 0; j < shape.getChildCount(); j++) {
		PShape subShape = shape.getChild(j);
		createExtrudedShape(subShape, depth, newShape);
	}

	return newShape;
}
 
Example 18
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 19
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 20
Source File: DwMeshUtils.java    From PixelFlow with MIT License 4 votes vote down vote up
static public void createPolyhedronShape(PShape shape, DwIndexedFaceSetAble ifs, float scale, int verts_per_face, boolean smooth){
    
    int type = -1;
    
    switch(verts_per_face){
      case 3: type = PConstants.TRIANGLES; break;
      case 4: type = PConstants.QUADS; break;
      default: return;
    }

    shape.setStroke(false);
    shape.beginShape(type);
//    shape.noStroke();
    
    int  [][] faces = ifs.getFaces();
    float[][] verts = ifs.getVerts();
    
    for(int[] face : faces){
      float nx = 0, ny = 0, nz = 0;

      int num_verts = face.length;
      
      // compute face normal
      if(!smooth){
        for(int i = 0; i < num_verts; i++){
          int vi = face[i];
          nx += verts[vi][0];
          ny += verts[vi][1];
          nz += verts[vi][2];
        }
        nx /= num_verts;
        ny /= num_verts;
        nz /= num_verts;
//        if(type == PConstants.QUADS){
          shape.normal(-nx, -ny, -nz);  // TODO: processing bug i guess
//        } else {
          shape.normal(nx, ny, nz); 
//        }
      }
      
      for(int i = 0; i < num_verts; i++){
//      for(int i = num_verts-1; i >= 0; i--){
        float[] v = verts[face[i]];
        if(smooth){
//          if(type == PConstants.QUADS){
//            shape.normal(-v[0], -v[1], -v[2]);  // TODO: processing bug i guess
//          } else {
            shape.normal(v[0], v[1], v[2]); 
//          }
        }
        shape.vertex(v[0]*scale, v[1]*scale, v[2]*scale);
      }
    }
    shape.endShape();
  }