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

The following examples show how to use processing.core.PShape#setName() . 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: DwSoftBody.java    From PixelFlow with MIT License 5 votes vote down vote up
protected void setShapeParticles(PApplet pg, PShape child){
  if(shp_particles == null){
    shp_particles = pg.createShape(PConstants.GROUP);
    shp_particles.setName("shp_particles (root)");
  } else {
    removeChilds(shp_particles);
  }
  child.setName("shp_particles");
  shp_particles.addChild(child);
}
 
Example 2
Source File: DwSoftBody.java    From PixelFlow with MIT License 5 votes vote down vote up
protected void setShapeMesh(PApplet pg, PShape child){
  if(shp_mesh == null){
    shp_mesh = pg.createShape(PConstants.GROUP);
    shp_mesh.setName("shp_mesh (root)");
  } else {
    removeChilds(shp_mesh);
  }
  child.setName("shp_mesh");
  shp_mesh.addChild(child);
}
 
Example 3
Source File: DwSoftBody.java    From PixelFlow with MIT License 5 votes vote down vote up
protected void setShapeWireframe(PApplet pg, PShape child){
  if(shp_wireframe == null){
    shp_wireframe = pg.createShape(PConstants.GROUP);
    shp_wireframe.setName("shp_wireframe (root)");
  } else {
    removeChilds(shp_wireframe);
  }
  child.setName("shp_wireframe");
  shp_wireframe.addChild(child);
}
 
Example 4
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 5
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 6
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 7
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;
}