processing.core.PShape Java Examples

The following examples show how to use processing.core.PShape. 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: ParticleSystem.java    From PixelFlow with MIT License 6 votes vote down vote up
public void initParticleShapes(){
  papplet.shapeMode(PConstants.CORNER);
  shp_particlesystem = papplet.createShape(PShape.GROUP);
  
  PImage sprite = createSprite(0);
  papplet.colorMode(PConstants.HSB, 360, 100, 100);
  
  for (int i = 0; i < PARTICLE_COUNT; i++) {
    PShape shp_particle = createParticleShape(particles[i], sprite);
    particles[i].setShape(shp_particle);
    if(i != IDX_MOUSE_PARTICLE){
      shp_particlesystem.addChild(shp_particle);
    }
  }
  papplet.colorMode(PConstants.RGB, 255, 255, 255);
}
 
Example #3
Source File: ParticleSystem.java    From PixelFlow with MIT License 6 votes vote down vote up
public PShape createParticleShape(DwParticle3D particle){
   
    PShape shp_particle = papplet.createShape(PShape.GEOMETRY);
    
    shp_particle.resetMatrix();
    shp_particle.translate(particle.cx, particle.cy, particle.cz);
    shp_particle.rotateX(papplet.random(PConstants.TWO_PI));
    shp_particle.rotateY(papplet.random(PConstants.TWO_PI));
    shp_particle.rotateZ(papplet.random(PConstants.TWO_PI));
    shp_particle.setStroke(false);
//    shp_particle.setFill(papplet.color(160));
    
    if(ifs == null) ifs = new DwIcosahedron(1);
//    if(ifs == null) ifs = new DwCube(1);
    DwMeshUtils.createPolyhedronShape(shp_particle, ifs, 1, 3, true);

    return shp_particle;
  }
 
Example #4
Source File: HeadSkullRenderVirus.java    From haxademic with MIT License 6 votes vote down vote up
protected void buildHeadModel() {
	// load model
	skullObj = p.loadShape( FileUtil.getPath("models/skull-realistic.obj"));
	objOrig = p.loadShape( FileUtil.getPath("models/Trump_lowPoly_updated.obj"));
	obj = p.loadShape( FileUtil.getPath("models/Trump_lowPoly_updated.obj"));
	
	PShapeUtil.scaleShapeToHeight(skullObj, p.height * 0.78f * 2f);
	PShapeUtil.scaleShapeToHeight(objOrig, p.height * 0.7f * 2f);
	PShapeUtil.scaleShapeToHeight(obj, p.height * 0.7f * 2f);
	
	// get centers of each face
	objFaceCenters = new PVector[obj.getChildCount()];
	for (int i = 0; i < obj.getChildren().length; i++ ) {
		PShape child = obj.getChild(i);
		if(child.getVertexCount() == 3) {
			objFaceCenters[i] = MathUtil.computeTriangleCenter( child.getVertex(0), child.getVertex(1), child.getVertex(2) ).copy();
		} else {
			objFaceCenters[i] = MathUtil.computeQuadCenter( child.getVertex(0), child.getVertex(1), child.getVertex(2), child.getVertex(3) ).copy();
		}
	}
	
	maxHeadExtent = PShapeUtil.getMaxExtent(obj);
}
 
Example #5
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 #6
Source File: DepthOfField_Demo.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 #7
Source File: PShapeUtil.java    From haxademic with MIT License 6 votes vote down vote up
public static PShape svgToUniformPointsShape(String fileName, float spacing) {
	// load svg and polygonize with Geomerative
	if(!RG.initialized()) RG.init(P.p);
	RShape rShape = RG.loadShape(fileName);
	rShape = RG.centerIn(rShape, P.p.g);

	RG.setPolygonizer(RG.UNIFORMLENGTH);
	RG.setPolygonizerLength(spacing);
	RPoint[] points = rShape.getPoints();

	// create PShape
	PShape svg = P.p.createShape();
	svg.beginShape(PConstants.POINTS);
	svg.stroke(255);
	svg.strokeWeight(1);
	svg.noFill();

	for(int i=0; i < points.length; i++){
		svg.vertex(points[i].x, points[i].y);
	}
	svg.endShape(P.CLOSE);

	return svg;
}
 
Example #8
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 #9
Source File: HaxMapDrawingTool.java    From haxademic with MIT License 6 votes vote down vote up
public void exportVertices() {
	String export = "";
	for( int i=0; i < _shapeGroups.size(); i++ ) {
		export += "#group#\n";
		ArrayList<PShape> curGroup = _shapeGroups.get(i);
		for( int j=0; j < curGroup.size(); j++ ) {
			PShape curShape = curGroup.get(j);
			PVector vertex;
			export += "#poly#";
			for (int k = 0; k < curShape.getVertexCount(); k++) {
				vertex = curShape.getVertex(k);
				if( k > 0 ) export += ",";
				export += vertex.x+","+vertex.y;
			}
			export += "\n";
		}
	}
	FileUtil.writeTextToFile(FileUtil.haxademicDataPath() + "text/mapping/mapping-"+SystemUtil.getTimestamp()+".txt", export);
}
 
Example #10
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 #11
Source File: PShapeUtil.java    From haxademic with MIT License 6 votes vote down vote up
public static void addTestStrokeToShape(PShape shape, float strokeWeight, float oscMult) {
	for (int i = 0; i < shape.getVertexCount(); i++) {
		PVector vertex = shape.getVertex(i);
		int strokeReplace = P.p.color(
				127 + 127f * P.sin(vertex.x * oscMult),
				127 + 127f * P.sin(vertex.y * oscMult),
				127 + 127f * P.sin(vertex.z * oscMult)
				);
		shape.noFill();
		shape.setStrokeWeight(i, 4);
		shape.setStroke(strokeReplace);
	}
	for (int j = 0; j < shape.getChildCount(); j++) {
		addTestStrokeToShape(shape.getChild(j), strokeWeight, oscMult);
	}
}
 
Example #12
Source File: Impeach.java    From haxademic with MIT License 6 votes vote down vote up
public void addFillToShape(PShape shape, float oscMult) {
	for (int i = 0; i < shape.getVertexCount(); i++) {
		PVector vertex = shape.getVertex(i);
		float zFade = P.map(vertex.z, 50, -50, 1, 0);
		int fillReplace = P.p.color(
			(127 + 127f * P.sin(vertex.x * oscMult)) * zFade,
			(127 + 127f * P.sin(vertex.y * oscMult)) * zFade,
			(127 + 127f * P.sin(vertex.z * oscMult)) * zFade
		);
		shape.setFill(i, fillReplace);
		shape.noStroke();
	}
	for (int j = 0; j < shape.getChildCount(); j++) {
		addFillToShape(shape.getChild(j), oscMult);
	}
}
 
Example #13
Source File: HaxMapDrawingTool.java    From haxademic with MIT License 6 votes vote down vote up
public void mousePressed() {
	super.mousePressed();
	_isPressed = true;
	
	
	// find closest vertex to mouse
	float closestPoint = 10;
	PShape curShape = null;
	PVector curVertex = null;
	for (int i=0; i < _shapes.size(); i++) {
		curShape = _shapes.get(i);
		for (int j = 0; j < curShape.getVertexCount(); j++) {
			curVertex = curShape.getVertex(j);
			float mouseDistToVertex = MathUtil.getDistance(p.mouseX, p.mouseY, curVertex.x, curVertex.y);
			if( mouseDistToVertex < closestPoint ) {
				// set z to 1 so that we know that we're dragging (this is a silly hack)
				curShape.setVertex(j, curShape.getVertex(j).x, curShape.getVertex(j).y, 1);
				_draggingShapes.add( curShape );
			}
		}
	}
}
 
Example #14
Source File: PShapeUtil.java    From haxademic with MIT License 6 votes vote down vote up
public static void exportMesh(PShape mesh) {
	StringBuilder verts = new StringBuilder();
	StringBuilder faces = new StringBuilder();
	final int vertsNum = mesh.getVertexCount();
	final PVector v = new PVector();
	for(int i=0; i < vertsNum; i+=3) {
		mesh.getVertex(i, v);
		verts.append("v " + v.x + " " + v.y + " " + v.z + "\n");
		mesh.getVertex(i+1, v);
		verts.append("v " + v.x + " " + v.y + " " + v.z + "\n");
		mesh.getVertex(i+2, v);
		verts.append("v " + v.x + " " + v.y + " " + v.z + "\n");
		faces.append("f " + (i+1) + " " + (i+2) + " " + (i+3) + "\n");
	}
	String outputStr = "o Sphere\n";
	outputStr += verts;
	outputStr += faces;
	FileUtil.writeTextToFile(FileUtil.haxademicOutputPath() + "text/model-"+SystemUtil.getTimestamp()+".obj", outputStr);
}
 
Example #15
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 #16
Source File: DwSoftBody.java    From PixelFlow with MIT License 5 votes vote down vote up
protected void printChilds(PShape shp, String indent){
  if(shp == null){
    return;
  }
  int num_childs = shp.getChildCount();
  
  System.out.println(indent+shp.getName()+": "+num_childs);
  for(int i = num_childs-1; i >= 0; i--){
    printChilds(shp.getChild(i), indent+"  ");
  }
}
 
Example #17
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 #18
Source File: DwSoftBall2D.java    From PixelFlow with MIT License 5 votes vote down vote up
@Override
public void createShapeWireframe(PGraphics pg, DwStrokeStyle style){
  PShape shp = createShape(pg);
  
  shp.setTexture(null);
  shp.setFill(false);
  shp.setStroke(true);
  shp.setStroke(style.stroke_color);
  shp.setStrokeWeight(style.stroke_weight);
  setShapeWireframe(pg.parent, shp);
}
 
Example #19
Source File: PShapeUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void setMaterialColor(PShape shape, int newColor) {
	for (int i = 0; i < shape.getVertexCount(); i++) {
		shape.setFill(i, newColor);
		shape.setStroke(false);
	}
	for (int j = 0; j < shape.getChildCount(); j++) {
		setMaterialColor(shape.getChild(j), newColor);
	}
}
 
Example #20
Source File: DemoAssets.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape objHumanoid() {
	if(objHumanoid == null) {
		objHumanoid = P.p.loadShape(FileUtil.getPath("haxademic/models/man-lowpoly.obj"));
		PShapeUtil.meshRotateOnAxis(objHumanoid, P.PI, P.Z);
		PShapeUtil.meshRotateOnAxis(objHumanoid, P.HALF_PI, P.Y);
	}
	return objHumanoid;
}
 
Example #21
Source File: Skylight_BulletPhysics_TowerDemolition.java    From PixelFlow with MIT License 5 votes vote down vote up
public void toggleDisplayWireFrame(){
  DISPLAY_WIREFRAME = !DISPLAY_WIREFRAME;
  for (BObject body : physics.rigidBodies) {
    PShape shp = body.displayShape;
    String name = shp.getName();
    if(name != null && name.contains("[wire]")){
      shp.setFill(!DISPLAY_WIREFRAME);
      shp.setStroke(DISPLAY_WIREFRAME);
    }
  }
  skylight.reset();
}
 
Example #22
Source File: Demo_VectorFlyer.java    From haxademic with MIT License 5 votes vote down vote up
public void addPointsToAttractors(PShape shape) {
	for (int i = 0; i < shape.getVertexCount(); i++) {
		PVector point = shape.getVertex(i);
		if(attractorExists(point) == false) {
			attractors.add( point ); 
			attractorsCount++;
			DebugView.setValue("attractorsCount", attractorsCount);
		}
	}
		
	for (int j = 0; j < shape.getChildCount(); j++) {
		PShape subShape = shape.getChild(j);
		addPointsToAttractors(subShape);
	}
}
 
Example #23
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 #24
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 #25
Source File: PShapeUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void meshFlipOnAxis(PShape shape, int axis) {
	for (int i = 0; i < shape.getVertexCount(); i++) {
		PVector v = shape.getVertex(i);
		if(axis == P.X) {
			shape.setVertex(i, v.x * -1f, v.y, v.z);
		} else if(axis == P.Y) {
			shape.setVertex(i, v.x, v.y * -1f, v.z);
		} else if(axis == P.Z) {
			shape.setVertex(i, v.x, v.y, v.z * -1f);
		}
	}
	for (int j = 0; j < shape.getChildCount(); j++) {
		meshFlipOnAxis(shape.getChild(j), axis);
	}
}
 
Example #26
Source File: Pshape.java    From warp10-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
  
  List<Object> params = ProcessingUtil.parseParams(stack, 1, 3, 5);
      
  PGraphics pg = (PGraphics) params.get(0);
  PShape shape = (PShape) params.get(1);
  
  if (2 == params.size()) {
    pg.parent.shape(shape);
  } else if (4 == params.size()) {
    pg.parent.shape(shape,
        ((Number) params.get(2)).floatValue(),
        ((Number) params.get(3)).floatValue()
    );
  } else if (6 == params.size()) {
    pg.parent.shape(shape,
        ((Number) params.get(2)).floatValue(),
        ((Number) params.get(3)).floatValue(),
        ((Number) params.get(4)).floatValue(),
        ((Number) params.get(5)).floatValue()
    );      
  }
  
  stack.push(pg);
      
  return stack;
}
 
Example #27
Source File: Demo_PShapeUtil_createExtrudedShape.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawApp() {
		p.background(0);
		PG.setBetterLights(p);

		// draw
		p.translate(p.width/2, p.height/2);
//		p.rotateY(P.map(p.mouseX, 0, p.width, -1f, 1f));
		p.rotateY(0.4f * P.sin(p.frameCount / 20f));
		p.noStroke();
		PShape curShape = shapesExtruded.get( curShapeIndex );
		PShapeUtil.drawTriangles(p.g, curShape, DemoAssets.textureNebula(), 1);
	}
 
Example #28
Source File: ParticleSystem.java    From PixelFlow with MIT License 5 votes vote down vote up
public void initParticleShapes(){
  papplet.shapeMode(PConstants.CORNER);
  shp_particlesystem = papplet.createShape(PShape.GROUP);
  
  PImage sprite = createSprite();
  for (int i = 0; i < PARTICLE_COUNT; i++) {
    PShape shp_particle = createParticleShape(particles[i], sprite);
    particles[i].setShape(shp_particle);
    shp_particlesystem.addChild(shp_particle);
  }
}
 
Example #29
Source File: DwDisplayUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public final void vertex(PShape pg, DwParticle3D v0){
  if(pg.is2D()){
    pg.vertex(v0.cx, v0.cy); 
  } else {
    pg.vertex(v0.cx, v0.cy, v0.cz); 
  }
}
 
Example #30
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;
}